Installing the SDK

This guide will help you setup the iOS SDK in your application and configure it to be controlled via REST APIs. The SDK is built to collect locations and related data in a battery efficient way, and has methods to start and stop data collection, and interact with the HyperTrack APIs.

If you're looking for an example integration, use the example-ios application.

[info] Minimum iOS version

The SDK is compatible with iOS 8 and above.

Install the dependency

The HyperTrack SDK is available via CocoaPods. Add the following lines to your Podfile to install the SDK.

In case you haven't setup CocoaPods for your app, refer to their website and setup a Podfile, and then add these lines.

[warning]

Remember to use the .xcworkspace file to open your project in Xcode, instead of the .xcodeproj file, from here on.

# Uncomment this if you are using frameworks
# use_frameworks!

target 'AppName' do
   pod 'HTTransmitter'
end

Configure the API key

Use your publishable key to configure the SDK.

We recommend doing this in your AppDelegate's -application:didFinishLaunchingWithOptions: method so that it will be set for the entire lifecycle of your app.

// AppDelegate.m
@import HyperTrack;
@import UIKit;

NSString * const HyperTrackPublishableKey = @"pk_YOUR_PUBLISHABLE_KEY";

@implementation AppDelegate

- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions {
    [HyperTrack setPublishableAPIKey:HyperTrackPublishableKey];
    [HTTransmitterClient initClient];
    return YES;
}

@end
import UIKit
import HTTransmitter

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        HyperTrack.setPublishableAPIKey("YOUR_PUBLISHABLE_KEY")
        HTTransmitterClient.initClient()
        return true
    }
}

Configure permissions

The SDK requires the following capabilities and permissions:

  1. In your project settings, under "Target", click on your target, go to the "Capabilities" tab and make sure "Background Modes" has been turned "ON", "Location updates" and "Background fetch" have been checked.
  2. Add NSLocationWhenInUsageDescription key to your Info.plist, if not added. Also add a value to the key describing the reason why the app accesses the user's location information.
  3. Add NSMotionUsageDescription key to you Info.plist to enable access to the accelerometer motion data. The SDK uses this for better ETA predictions.

[info] Location permissions

The SDK is compatible with both Location - Always and Location - When in use permissions. If your app uses the former, you need not add the second one.

Connect the SDK

Initialise the SDK connection to the server by passing the driver id to the connectDriverWithDriverID method. This should be done in the applicationDidBecomeActive method of your AppDelegate.m.

[info] Driver entity

If you don't have a driver id, refer to the creating a Driver server-side API.

[[HTTransmitterClient sharedClient] connectDriverWithDriverID:@"YOUR_DRIVER_ID" completion:^(NSError * _Nullable error) {
        NSLog(@"Error : %@", error);
    }];
HTTransmitterClient.sharedClient().connect(driverID: "driver_id") { (error) in
    print("did fail to connect \(error)")
}

Once the SDK has been connected, it is ready to be controlled by the server-side APIs.

Was this helpful? Yes, thanks! Not really

results matching ""

    No results matching ""