Chirp Connect macOS SDK

Getting Started

Import the SDK

Import the SDK into your project by dragging and dropping the .framework file into your Xcode project.

“Set ‘Copy items if needed’ if the framework is not already within your project folder.”

Add the framework

Add framework to ‘Linked Frameworks and Libraries’.

Under the Info tab in the Project Settings, add a Custom iOS Target Property called Privacy - Microphone Usage Description.

Instantiate the SDK.

Include the SDK and its associated licence header:

#import <ChirpConnect/ChirpConnect.h>
#import "Licence.h"

And instantiate the SDK with your own app key and secret:

self.connect = [[ChirpConnect alloc] initWithAppKey:TEST_APP_KEY
                                     andSecret:TEST_APP_SECRET];

Next we have to configure the SDK by setting the licence string.

Your default licence is retrieved via the Chirp Admin Centre API, allowing it to be updated over-the-air.

[self.connect getLicenceStringWithCompletion:^(NSString * _Nullable licence, NSError * _Nullable error) {

    // set the licence
    NSError *licenceError = [self.connect setLicenceString:licence];

    // start the SDK
    NSError *startError = [self.connect start];

}];

Alternatively, your licence can be set without making a network call (completely offline) if you have been provided a licence file.

// set the licence
[self.connect setLicenceString:<YOUR LICENCE STRING>];

// start the SDK
NSError *error = [self.connect start];

You are now ready to send and receive data. First we will generate some random data to send, and send it using the SDK. When the send: method is called, Connect will encode the data and send it out through the device’s loudspeaker.

NSData *data = [self.connect randomPayloadWithLength:self.connect.maxPayloadLength];
NSError *error = [self.connect send:data];

To receive this data on a second device, simply implement the received: callback block:

[self.connect setReceivedBlock:^(NSData * _Nonnull data) {
    NSLog(@"received %@", data);
}];

You are now ready to start using Connect in your own application. For more advanced features, please look at the ChirpConnect/ChirpConnect.h header file, which lists the complete set of available methods.

Getting Started (Swift)

Add a bridging header.

Add a new Objective-C file to your Swift project, Xcode will prompt if you want to configure your project with a bridging header. Press yes. Once the bridging header is added to your project, you can delete the Objective-C file if you want to.

Inside the bridging header add the following line, this now makes the Chirp Connect framework available throughout your project’s Swift files.

#import <ChirpConnect/ChirpConnect.h>

Instantiate the SDK.

Instantiate the SDK with your own app key and secret:

let connect: ChirpConnect = ChirpConnect(appKey: TEST_APP_KEY, andSecret: TEST_APP_SECRET)

Next we have to configure the SDK by setting the licence string.

Your default licence can be retrieved over-the-air.

connect.getLicenceString {
  (licence: String?, error: Error?) in
  if error == nil {
    if let licence = licence {
      connect.setLicenceString(licence)
      connect.start()
    }
  }
}

Alternatively, your licence can be set without making a network call (completely offline) if you have been provided a licence file.

let licenceError: Error = connect.setLicenceString(<YOUR LICENCE STRING>)
let startError: Error = connect.start()

You are now ready to send and receive data. First we will generate some random data to send, and send it using the SDK. When the send: method is called, Connect will encode the data and send it out through the device’s loudspeaker.

let data: Data = connect.randomPayload(withLength: UInt(connect.maxPayloadLength))
connect.send(data)

To receive this data on a second device, simply implement the received: closure:

connect.receivedBlock = {
  (data : Data) -> () in
  if let data = data {
    print(String(data: data, encoding: .ascii))
    return;
  }
};