DATA ACQUISITION SDK FOR iOS

In this detailed guide, we take you through the steps required to integrate the library with your  app.


Pre-requisites

Deployment target:

  • iOS 8.0

 

Tools required:

  • Xcode 8 and above

 

Integrating the library

Sending custom data

Tracking location

 

Integrating the Library

Step1: Create/open your iOS application in Xcode.

integrate library iOS1

 

Step 2: Build your app

Once the app is open in XCode, build it to ensure that it's running smoothly.

build app iOS1

 

Step 3: Import the library

Open up the library folder and drag "libDataAcquisitionSDK.a" and "/include" to your Xcode project:

import library iOS1

 

Step 4: Add required dependencies

The library requires CoreLocation from iOS SDK as a dependency.

import_depencies iOS

 

Note: If your project already has these dependencies, you don't need to add them again.

 

Step 5: Set up the library and build

Now you have imported the library and added the required dependencies.

Import the main class:

    #import "include/DataAcquisitionSDK/DataAcquisitionSDK.h"

 

You can now refer the class from the library in your application.

    @property (strong, nonatomic) DataAcquisitionSDK *client;

import_classes iOS

 

To initiate the library, use the following code:

    DataAcquisitionSDK *clientInstance = [DataAcquisitionSDK shared];
    [clientInstance setup];
    

 

If you want to enable debug mode please use the following statement:

    clientInstance.debug = YES;

setup_sdk iOS

 

Thats it!

Build the project. If there are no errors, you have successfully integrated the library with your application.

 

[stopped here]

 

Sending Custom Data

Step1: Create and send custom data

Using the following codes, create your custom data or event:

  NSDictionary *userData = @{
@"email":@"aSdF@aSdF.cOm",
@"new_user":@"true"
};

[self.client track: userData];

 

If you want to create a new custom event, you can do so with the following code:

    NSNumber* timestamp = [NSNumber numberWithLongLong:(long long)([[NSDate date] timeIntervalSince1970])];
[self.client track:@{
@"app_name": @"Test App",
@"event_date": timestamp,
@"event_type": @"launch",
@"seconds_used": @"100",
@"permissions": @"comma,delimited,list"
}];

 

send custom data iOS1

 

Step 2: Build and run project

send custom data build_project iOS1

 

Run the application if there are no errors.

send custom data build_project iOS2

 

Thats it! You can now send your custom data/event!

 

Tracking Location

Step 1: Add location usage descriptions in info.plist

Add the required location usage descriptions for your application. These will be shown to users in the prompt dialog when your app requests permission from users.

Copy the following code to your application's info.plist:

  <key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>Please give access to your location!</string>

<key>NSLocationAlwaysUsageDescription</key>
<string>Please give access to your location!</string>

<key>NSLocationUsageDescription</key>
<string>Please give access to your location!n</string>

<key>NSLocationWhenInUseUsageDescription</key>
<string>Please give access to your location!</string>

 

enable_location_permissions iOS1

 

Step 2: Enable background modes for location capturing

Enable location capture and background fetch modes.

enable_background_modes iOS1

 

Step 3: Import location manager

Import the location manager class and other required properties:

@import CoreLocation;

 

Add the following properties:

@property BOOL locationOn;
@property BOOL _isBackgroundMode;
@property BOOL _deferringUpdates;
@property (strong, nonatomic) CLLocationManager *locationManager;

import_location_classes iOS1

 

Step 4: Setup location access methods

Add a method to initiate the location access request using location manager class:

- (void) turnOnLocationTracking {
if([CLLocationManager locationServicesEnabled]){

NSLog(@"Location Services Enabled");

if([CLLocationManager authorizationStatus] != kCLAuthorizationStatusDenied){
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
self.locationManager.pausesLocationUpdatesAutomatically = NO;
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[self.locationManager requestAlwaysAuthorization];

[self.locationManager startUpdatingLocation];
}
}
}

setup location access methods iOS1

 

Optional: You may also add a method for stopping location capture as well.

- (void) turnOffLocationTracking {
if([CLLocationManager locationServicesEnabled]){

//NSLog(@"Location Services Enabled");

if([CLLocationManager authorizationStatus] != kCLAuthorizationStatusDenied){
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
[self.locationManager stopUpdatingLocation];
self.locationOn = false;
}
}
}

 

Step 5: Implement location manager delegate methods

Implement the location manager delegate methods, these are the callback methods that are fired when a location event occurs:


- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
    NSLog(@"locationManager fired");
    CLLocation *location = [locations lastObject];
    if(self.locationOn != true){
        self.locationOn = true;
    }
}

- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
    NSLog(@"didFailWithError: %@", error);
}

- (void) locationManager:(CLLocationManager *)manager didFinishDeferredUpdatesWithError:(NSError *)error {
    self._deferringUpdates = NO;
    //do something
}

 

Once the location is captured, you must call the following method using ‘track location’:

    DataAcquisitionSDK *client = [DataAcquisitionSDK shared];
    [client trackLocation:location];

 

Copy this code to the didUpdateLocations callback method as follows.


- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
    NSLog(@"locationManager fired");
    CLLocation *location = [locations lastObject];
    
    if(self.locationOn != true){
        self.locationOn = true;
    }
    
    DataAcquisitionSDK *client = [DataAcquisitionSDK shared];
    [client trackLocation:location];
    
}

 

location_delegate_methods iOS1

 

Build the project again to ensure there are no errors.

build_project iOS1

 

Step 6: Call ‘turn on location’ capture method and run project

You now have all the methods required to capture location and send it via the library.

Use the following lines of code to initiate location capture:

    [self turnOnLocationTracking];

call_location_tracking iOS1

 

Build and run the project.

start_sending_location_data iOS1

 

That's it!

You have now started tracking location via DataAcquisitionSDK

 

 

If you face any difficulties, do reach out to support@quadrant.io.