Contacthub SDK in Objective-C/Swift
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
ContactHub.xcodeproj
Hub
HubTests
Resources
SwiftExample
.gitignore
CONTRIBUTING.md
ContactHub.podspec
LICENSE
README.md

README.md

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.

Disclaimer

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.

Note:

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

Requirements

  • iOS 8.0+
  • Xcode 9.4+

How to use

Note:

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: "john@example.com", nodeId: node.nodeId)
node.add(customer) { (customer, error) in
    guard error == nil else {
        let error = error!
        print("Error creating customer: \(error.localizedDescription)")
        return
    }

    guard let customer = customer else {
        print("Error: missing customer")
        return
    }
   // 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()
properties.name = "generic name"
properties.extraProperties = ExtendedPropertyObject(key: "hello", value: ["hello": "world" as NSObject])

event.properties = properties

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

Integration

CocoaPods

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

    or:

  • Create a new one with the pod init command

pod 'ContactHub', :git => "https://github.com/contactlab/contacthub-sdk-objc.git"

Then, run the following command:

pod install
```bash

### Carthage

[Carthage](https://github.com/Carthage/Carthage) is a decentralized dependency manager, which builds your dependencies and provides you with binary frameworks.

You can install [Carthage](https://github.com/Carthage/Carthage) with [Homebrew](http://brew.sh/) using the following command:

```bash
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.

Test

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.

    Note:

    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.

Acknowledgments