You should have a token based iOS app.
Guide focus: Setting up Everlink’s iOS SDK to enable sonic-key to token exchange.
There are two core elements to consider in this process, Set Up and Usage.
Set Up: Please follow the steps below to get started:
The Everlink SDK uses the microphone to record audio. Add Privacy - Microphone Usage Description in the info.plist file for microphone access.
1) Add EverLink SDK to your app
Step 1 requires account approval
Usage: After the client app is set up, you are ready to begin verifying and identifying devices, you can now:
The code below demonstrates how to add Everlink to an existing ViewController.
Change all instances of ViewController example with the name of your View Controller, and let
myAppID to your key, which you can find in the account page:
1) Detect Code
When you want to detect an audio code simply call: startRecording(isOffline)
// Other codes... @IBAction func startRecording(_ sender: Any) { //to start listening for a code call: connectObj.startRecording(isOffline: false) } // Other codes... @IBAction func stopRecording(_ sender: Any) { //to stop listening call: connectObj.stopRecording() } // Other codes...Which will cause the device to start listening for an audio code, on successful detection we will return the identifying token of the heard device via the onAudioCodeReceived method.
2) Send Code
When you want to start emitting an audio code simply call: startEmitting()
// Other codes... @IBAction func playSound(_ sender: Any) { //to start emitting an audio code call: connectObj.startEmitting() } // Other codes... @IBAction func stopPlaying(_ sender: Any) { //to stop emitting call: connectObj.stopEmitting() } // Other codes...
You can alternatively pass a token as an argument and its audio code will play, as shown below:
// Other codes...
@IBAction func playToken(_ sender: Any) {
//to start emitting an audio code call:
connectObj.startEmittingToken(token: "exampleToken12345", isOffline: false)
}
// Other codes...
Function startEmittingToken(token, isOffline) now takes a boolean as an argument.
If this argument is true then the device will try to fetch the audio code it will emit locally,
rather than contacting our servers, this will allow your users to be offline.
Create token
If you wish to manually generate a new user token call: newToken(startDate)
// Other codes...
@IBAction func newToken(_ sender: Any) {
//Generate a new user token to save in your database
connectObj.newToken(startDate: "")
}
// Other codes...
Function newToken(startDate) takes a validity start date in the form ‘YYYY-MM-DD’.
The token will be valid for two weeks after this date.
If no validity date is provided then it will be the current date.
Downloading Tokens
(Only needed if you want the SDK to work offline)
To download the audio code associated with a token so it can later be played or detected offline, call
function saveSounds() passing it an array of tokens:
// Other codes...
@IBAction func saveTokens(_ sender: Any) {
//Save an array of tokens and their corresponding audio codes.
let array = ["exampleToken12345", "exampleToken12346", "exampleToken12347"]
connectObj.saveSounds(tokensArray: array)
}
// Other codes...
Call clearSounds() To delete all downloaded tokens and their corresponding audio codes