Contacthub SDK in Objective-C/Swift
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

Contacthub Objective-C SDK

Version 1.58.0 beta

This repository contains the official Objective-C SDK for Contacthub. It is also fully compatible with Swift 4.1.


The current version is intended as an alpha release and should not be used in a production environment, as we still reserve the right to change the underlying APIs.


Because iOS applications are considered untrusted, only the APIs that can be accessed with an untrusted source have been implemented in this SDK.


  • iOS 8.0+
  • Xcode 9.4+

How to use


For simplicity, we use object names as they are available in Swift. If you are using Objective-C please add the CHB prefix.

Remember to import the ContactHub framework:

import ContactHub

or in Objective-C:

#import <ContactHub/ContactHub.h>

Node instantiation

Every request is performed on a Node in a Workspace. Your application will identify you as a source and authenticate you with a sourceToken.

let node = Node(workspaceId: "<# WORKSPACE_ID #>", nodeId: "<# NODE_ID #>", sourceToken: "<# SOURCE_TOKEN #>")

Create a customer

let customer = Customer(firstName: "John", lastName: "Appleseed", email: "", nodeId: node.nodeId)
node.add(customer) { (customer, error) in
    guard error == nil else {
        let error = error!
        print("Error creating customer: \(error.localizedDescription)")

    guard let customer = customer else {
        print("Error: missing customer")
   // Now you can create an event for this customer

Create an event for a pre-existing customer

let customerId = customer.objectId

let event = Event()
event.customerId = customerId
event.context = .mobile
event.type = .genericActiveEvent

let properties = GenericProperties() = "generic name"
properties.extraProperties = ExtendedPropertyObject(key: "hello", value: ["hello": "world" as NSObject]) = properties

node.add(event) { (error) in
    guard error == nil else {
        let error = error!
        print("Error creating event: \(error.localizedDescription)")
    print("Event created")



CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

gem install cocoapods

To integrate Contacthub into your Xcode project using CocoaPods:

  • Specify it in your Podfile if you already have one


  • Create a new one with the pod init command

pod 'ContactHub', :git => ""

Then, run the following command:

pod install

### Carthage

[Carthage]( is a decentralized dependency manager, which builds your dependencies and provides you with binary frameworks.

You can install [Carthage]( with [Homebrew]( using the following command:

brew update
brew install carthage

To integrate Contacthub into your Xcode project using Carthage, specify it in your Cartfile:

github "contactlab/contacthub-sdk-objc"

Run carthage update --platform iOS to build the framework and drag the built ContactHub.framework into your Xcode project.

Manually add Contacthub as subproject

Add the ContactHub Xcode project to your own. Then add the ContactHub framework to the target dependencies of your app.


In order to run the tests you should provide a workspaceId, nodeId and sourceToken as environmental variables for the test phase.

  • Select the ContactHub scheme and use the menu Product > Scheme > Edit Scheme... or press ⌘<.

  • On the left side of the new panel, select the Test.

  • Expand the Environment Variables section on the right and enter the arguments.


    Ensure that you deselect the Use the Run action's arguments and environment variables box.

Test Environmental Arguments

  • Run the tests locally on your machine using the menu Product > Test or press ⌘U.