Nodle SDK - iOS API and Configuration

The SDK receives configuration remotely from Nodle servers as well as statically using API calls. The static configuration always takes precedence over the remote configuration.

Nodle SDK Api

To interact with the SDK you need to call the Nodle.sharedInstance method that will give you an Instance of the INodle class. The following are all the public methods for the Nodle API.

import UIKit
import SwiftCBOR
import SwiftProtobuf
import NodleSDK
import SQLite
import CoreLocation
import CoreBluetooth

let nodle = Nodle.sharedInstance

start

public fun start(public_key: String)

Immediately starts the Nodle SDK

Example:

Nodle().start("ss58:public_key");

isStarted

public fun isStarted(): Boolean

Checks if the Nodle SDK is started

Example:

let sdkStarted = Nodle().isStarted()

isScanning

public fun isScanning(): Boolean

Checks if the Nodle SDK is currently scanning the BLE neighborhood. This is useful if you want to show that the SDK is working.

Example:

let sdkScanning = Nodle().isScanning()

stop

public fun stop()

Immediately stops the Nodle SDK

Example:

Nodle().stop();

clear

public fun clear()

Clear any configs by Nodle SDK

Example:

Nodle().clear();

getVersion

public fun getVersion(): String

Get the version identifier of the Nodle SDK.

Example:

let nodleSdkVersion = Nodle().getVersion();

getEvents

public fun getEvents(): NodleEvent

Get the raw bluetooth events from the Nodle SDK with the following type:

Example of available return event classes below:

Example:

nodle.getEvents { event in
    // collect the NodleEvent events by chosing a type
    switch event.type {
        case .BlePayloadEvent:
            let payload = event as! NodleBluetoothRecord
            print("Bluetooth payload available \(payload.device)")
            break
        case .BleStartSearching:
            print("Bluetooth started searching")
            break
        case .BleStopSearching:
            print("Bluetooth stopped searching")
            break
        @unknown default:
            print("Failed to get any event")
    }
}

The following data can be collected from the NodleEventType:

The following data can be collected from the NodleBluetoothScanRecord:

The following data can be collected from the NodleBluetoothEvent:

The following data can be collected from the NodleBeaconScanRecord:

The following data can be collected from the NodleBeaconEvent:

The table shows rational range for the beacon devices that are found:

registerNodleBackgroundTask

public fun registerNodleBackgroundTask()

Register the Nodle SDK background task

Example:

Nodle().registerNodleBackgroundTask()

scheduleNodleBackgroundTask

public fun scheduleNodleBackgroundTask()

Schedules the Nodle SDK background task

Example:

Nodle().scheduleNodleBackgroundTask()

config

public fun config(path: Path)

public fun <T> config(key: String, value: T)

configure the SDK either by supplying a json file located in ../config.json or by directly configuring a key. An example of a json configuration look like this:

{
  "ble": {
    "scan": {
      "duration-msec": 10000,
      "interval-msec": 90000,
      "interval-x-factor": 1
    }
  },
  "dtn": {
    "use-cellular": false
  }
}

the following are the table of all the keys available and their description:

there is another table that will allow you to configure our SDK background modes. There are 4 available modes: NONE, ECO, NORMAL, AGGRESSIVE for the NodleSDK please check them in the table below:

Example:

import UIKit
import SwiftCBOR
import SwiftProtobuf
import NodleSDK
import SQLite
import CoreLocation
import CoreBluetooth

// load the json config located in your app folder config.json
let bundle = Foundation.Bundle(identifier: "io.nodle.apptest.AppTest")
        
// path for the file in the project
let path = bundle!.path(forResource: "config", ofType: "json")

// or you can manually set the entries, for instance
Nodle().config("dtn.use-cellular", false);

// background mode selected - foreground only
Nodle().config("cron.ios-bg-mode", 0);

// then proceed to start Nodle
Nodle().start()

Last updated