iOS

1
Last updated 17 days ago

Get started by plugging in the SDK in your iOS app

The HyperTrack SDK for iOS is ~900 KBs in size, and consumes 10% battery per day on average.

Sign up here to get your keys, and the follow the steps below to add the SDK.

Step 1: Add SDK

Ensure that you have CocoaPods installed in your system; if not follow these instructions to install it. If you are not using CocoaPods in your project, then open terminal and run the following command from your project directory.

# Change directory to your project's root directory and run the following command.
$ pod init

Open the Podfile that was created as a result of the above command and add an entry for HyperTrackCore SDK to this file.

Podfile
# Uncomment the next line to define a global platform for your project
platform :ios, '9.0'
target <Your App Target> do
# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!
# Pods for YourApp
pod 'HyperTrackCore'
...
target <Your App Tests Target> do
inherit! :search_paths
# Pods for testing
end
target <Your App UI Tests Target> do
inherit! :search_paths
# Pods for testing
end
end

Go to terminal and run the following command to add the SDK to your project.

$ pod install

Close the <Your Project>.xcodeproj file and open <Your Project>.xcworkspace

Step 2: Enable location & motion permissions

To configure Always authorization for location services, add following entries to the Info.plist file.

Configuration for Always authorization of location services

To configure When-In-Use authorization for location services, add following entries to the Info.plist file.

Configuration for When-In-Use authorization of location services

Step 3: Enable background modes

Turn on Background Modes and make sure the following three options are selected:

  1. Location updates

  2. Background Fetch

  3. Remote Notifications

Turning on background modes

Step 4: Get permissions

Get location and activity permissions from the app user on the device.

Swift
Objective-C
ViewController.swift
import HyperTrackCore
...
// Make sure to go to the Info tab in your app settings
// and add permission strings for "Privacy - Location Always Usage Description"
// and "Privacy - Motion Usage Description"
HyperTrackCore.requestLocationPermission { (error) in
/// handle error if any
}
HyperTrackCore.requestActivityPermission { (error) in
/// handle error if any
}
ViewController.m
@import HyperTrackCore;
...
// Make sure to go to the Info tab in your app settings
// and add permission strings for "Privacy - Location Always Usage Description"
// and "Privacy - Motion Usage Description"
[HTCore requestLocationPermissionWithCompletionHandler:^(HTCoreError * _Nullable error) {
/// handle error if any
}];
[HTCore requestActivityPermissionWithCompletionHandler:^(HTCoreError * _Nullable error) {
/// handle error if any
}];

Step 5: Initialize SDK

Initialize the SDK with your publishable key in your AppDelegate file.

Swift
Objective-C
AppDelegate.swift
import HyperTrackCore
...
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
...
HyperTrackCore.initialize(publishableKey: PUBLISHABLE-KEY) { (error) in
/// perform post initialization actions: you could request authorization here.
/// handle error if any
}
...
return true;
}
AppDelegate.m
@import HyperTrackCore;
...
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
...
[HTCore initializeWithPublishableKey:@"PUBLISHABLE-KEY" completionHandler:^(HTCoreError * _Nullable error) {
/// perform post initialization actions: you could request authorization here.
/// handle error if any
}];
...
return YES;
}

Step 6: Change build settings

Before you compile your code, make sure you change the Swift Language Versionto 4.1 by clicking on Pods project in the Project Navigator and selecting HyperTrackCore Target. Go to Build Settings tab and update Swift Language Versionto 4.1

Swift Version

Step 7: Run your app

You are all set. It’s now time to compile and run your app.

Congratulations on configuring your app with the SDK