datacollector-ios-sdk

Telenav DataCollector iOS SDK.

Installation

Preparations

Install CocoaPods on your computer:

sudo gem install cocoapods

For more information follow CocoaPods Installation Guides

Installation

  1. Create a Podfile, and add your dependencies:

    target 'MyAppTarget' do
        use_frameworks!
    end
    

    For more information follow Podfile Guides

  2. Add the following lines to the beginning of Podfile.

    plugin 'cocoapods-art', :sources => [
        'telenav-cocoapods'
    ]
    
  3. Add DataCollector dependency in your target (after use_frameworks!):

    pod 'TelenavSDKDataCollector'

  4. Run pod repo-art update telenav-cocoapods in your project directory.

    And then: pod install .

  5. Open App.xcworkspace and build.

Usage of DataCollector SDK

Initialization

  1. Import the library into your app:

    Swift:

    import TelenavSDKDataCollector
    

    Objective-C:

    @import TelenavSDKDataCollector;
    
  2. Create SDK options with account credentials:

Swift: swift let options = TNDataCollectorSDKOptionsBuilder() .apiKey("API_KEY_PROVIDED_BY_TELENAV") .apiSecret("API_SECRET_PROVIDED_BY_TELENAV") .cloudEndPoint("CLOUD_ENDPOINT_PROVIDED_BY_TELENAV") .appInfo(name: "APPLICATION_NAME", version: "APPLICATION_VERSION") .userId("USER_ID") .deviceGuid("DEVICE_ID") .build()

Objective-C:
```objc
TNDataCollectorSDKOptionsBuilder * builder = [TNDataCollectorSDKOptionsBuilder new];
    [builder apiKey:@"API_KEY_PROVIDED_BY_TELENAV"];
    [builder apiSecret:@"API_SECRET_PROVIDED_BY_TELENAV"];
    [builder cloudEndPoint:@"CLOUD_ENDPOINT_PROVIDED_BY_TELENAV"];
    [builder appInfoWithName:@"APPLICATION_NAME" version:@"APPLICATION_VERSION"];
    [builder userId:@"USER_ID"];
    [builder deviceGuid:@"DEVICE_ID"];
TNDataCollectorSDKOptions * options = [builder build];
```
  1. Initialize Data Collector Service with options:

    Swift:

    TNDataCollectorService.initialize(sdkOptions: options)
    

    Objective-C:

    [TNDataCollectorService initializeWithSdkOptions:options];
    
  2. Now you can get Data Collector Client from Service:

    Swift:

    let client = TNDataCollectorService.sharedClient
    

    Objective-C:

    TNDataCollectorClient * client = TNDataCollectorService.sharedClient;
    

Send events

  1. Use Client method to send any supported event:

    Swift:

    func send(event: TNEvent)
    

    Objective-C:

    [client sendWithEvent: event];
    

    This method returns an error (TNDataCollectorError) in case of event is not supported or Client was not properly configured

  2. Supported events are:

    TNFavoriteEvent
    TNRemoveAllFavoritesEvent
    TNEntityActionEvent
    TNEntityCacheActionEvent
    TNSetHomeEvent
    TNSetWorkEvent
    TNStartEngineEvent
    TNStopEngineEvent
    TNGpsProbeEvent
    TNGyroscopeEvent
    TNAccelerometerEvent
    TNLinearAccelerationEvent
    TNGravityEvent
    
  3. Use apropriate builders in order to construct valid event before sending.

    For example TNGpsProbeEvent:

    Swift:

    let item = TNProbeListItemBuilder()
        .lat(55).lon(73)
        .locationTime(time)
        .altitude(20000.3)
        .horizontalAccuracy(5)
        .verticalAccuracy(6)
        .speed(200)
        .direction(.SW)
        .headingAngle(359)
        .build()
    let gpsEvent = TNGpsProbeEventBuilder().items([item]).build()
    TNDataCollectorService.sharedClient?.send(event:gpsEvent)
    

    Objective-C:

    TNProbeListItemBuilder * itemBuilder = [TNProbeListItemBuilder new];
    [[itemBuilder lat:55] lon:73];
    [itemBuilder locationTime:[NSDate new]];
    [[itemBuilder altitude: 20000.3] verticalAccuracy:6];
    [itemBuilder speed:200];
    [itemBuilder horizontalAccuracy:5];
    [itemBuilder direction:TNHeadingDirectionTypeSW];
    [itemBuilder headingAngle:359];
    TNProbeListItem * item = [itemBuilder build];
    TNGpsProbeEventBuilder * eventBuilder = [TNGpsProbeEventBuilder new];
    TNGpsProbeEvent * event = [[eventBuilder addItem:item] build];
    [client sendWithEvent: event];
    

Subscribe to event type

  1. Use Client method subscribe in order to subscribe to certain event type:

    Swift:

    func subscribe(consumerWithName: String, forEventTypes: [TNEventType], withCallBack: (TNEvent)->())
    

    Provide: - consumer name as an identifier for Data Collector, - the list of event types to subscribe to, - the callback to be executed when event of the type happens.

    This method returns an error (TNDataCollectorError) in case of consumer name is empty or consumer already exists for the event type etc.

    For example:

    Swift:

    TNDataCollectorService.sharedClient?.subscribe(consumerWithName: "MyConsumerName", 
            forEventTypes: [TNEventType.Sensor.linearAcceleration, TNEventType.User.setHome],
            withCallBack: { [weak self] (event) in
                                print(event)
                          })
    

    Objective-C:

    TNDataCollectorClient * client = TNDataCollectorService.sharedClient;
    NSArray<TNEventType *> * types = TNSensorEventType.values;
    [client subscribeWithConsumerWithName: @"MyConsumerName"
                            forEventTypes:types
                             withCallBack:^(TNEvent * _Nonnull event) {
        NSLog(@"%@: %@", [NSDate new], event.eventName);
    }];
    

    You can use values property of TNEventType to subscribe for all kinds of some events: - TNEventType.Sensor.values - for all events from sensors, - TNEventType.values - for all possible supported events

  2. When needed use unsubscribe method of Client:

    Swift:

    func unsubscribe(consumerWithName: String, forEventTypes: [TNEventType])
    

DataSource

Please read Readme for DataSource library