Plug in the iOS SDK

In this guide, we will setup the HyperTrack SDK in your iOS app. At the end of this guide, you would be able to track a user in real time. You would see trips that the user made along with polylines, time & distance travelled, and places that the user stopped at along with time they spent at that place.

In case you are not using iOS, you can refer to the Android version.

Step 1: Install the SDK

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] Xcode project

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

use_frameworks!

target 'AppName' do
   pod 'HyperTrack'
end

Step 2: Configure the SDK

Now that the SDK has been installed, you can use the SDK methods inside Xcode. Configure your publishable key and initialise the SDK.

[warning] Objective C config

In case your app is in Objective C, edit the Build Settings of the Pods Project. Change the Use Legacy Swift Language Version flag from Unspecified to No for “Alamofire”, “CocoaMQTT” and “HyperTrack” libraries.

import HyperTrack

HyperTrack.initialize("pk_publishableKey")
@import HyperTrack;

[HyperTrack initialize:@"pk_publishableKey"];

Step 3: Add background capability to your app

Go to the capabilities tab in your app settings, scroll to background modes and switch it on. Select "Location updates", "Background fetch" and "Remote notifications".

Step 4: Add permission strings to your Info.plist

Go to the Info tab in your app settings and add permission strings for "Privacy - Location Always Usage Description" and "Privacy - Motion Usage Description"

Step 5: Configure location permissions

The SDK is only compatible with the Location - Always permission. You can use the included utility methods to request permission, in case you feel the need to.

HyperTrack.requestAlwaysAuthorization()
[HyperTrack requestAlwaysAuthorization];

Step 6: Create SDK user

To be able to identify the device, the SDK needs a user id. You can create a new user user on the SDK, and specify a string identifier. This is a network call that requires the device to be online.

[info] User already created?

You can set an existing user id, in case you have created an user id via the backend API using the HyperTrack.setUserId("YOUR_USER_ID") method in the SDK.

HyperTrack.createUser(John Doe) { user, error in
    if (user != nil) {
        // User was created, do stuff here
        HyperTrack.startTracking()
    }
}
[HyperTrack createUser:@"John Doe" completionHandler:^(HyperTrackUser * _Nonnull user, HyperTrackError * _Nonnull error) {
    if (user) {
        // User was created, do stuff here
      [HyperTrack startTracking];
    } else {
      NSLog(@"%@", error);
    }
  }
]

Step 7: Start the SDK

To start tracking the user, use the startTracking method. You can keep the SDK on throughout the day, or turn it off if you want to stop tracking the user at any point of time using the HyperTrack.stopTracking() method.

HyperTrack.startTracking()
[HyperTrack startTracking];

Step 8: View dashboard

Install your app with the HyperTrack SDK on a device and begin tracking on the Dashboard. You would see the user’s current state on the HyperTrack dashboard. If you click on the user, you should be able to view the user's trips and stops.

Step 9: Stop the SDK

To stop tracking the user, use the stopTracking method.

HyperTrack.stopTracking()
[HyperTrack stopTracking];

results matching ""

    No results matching ""