HyperTrack iOS SDK Setup

To use the HyperTrack SDK on iOS you we first need to setup the SDK into our environment.

In case you are not using iOS, you can refer to the Android version, or the React Native 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.

For Xcode 9

use_frameworks!

target 'AppName' do
   pod 'HyperTrack'

    post_install do |installer|
        installer.pods_project.targets.each do |target|
            target.build_configurations.each do |config|
                config.build_settings['SWIFT_VERSION'] = '3.2'
            end
        end

        Dir.glob('Pods/SQLite.swift/Sources/SQLite/**/*.swift').each { |path|
            begin
                text = File.read(path)
                text = text.gsub(/import CSQLite/, 'import SQLite3')
                File.open(path, 'w') { |file| file.puts text }
                rescue Exception
                puts "Unable to patch #{path}: #{$!}"
            end
        }
    end
end

For Xcode 8

use_frameworks!

target 'AppName' do
   pod 'HyperTrack', '0.4.56'
end

Now run pod install from the command line.

[info] Minimum Deployment target

HyperTrack SDK support iOS 8.0 and above as deployment targets.

[warning] Xcode project

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

[warning] Using Xcode 9

If you are using Xcode 9, then you might face compilation issues related to zlib and Sqlite. To resolve them, follow the steps mentioned here.

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.

import HyperTrack

HyperTrack.initialize("YOUR_PUBLISHABLE_KEY")

[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” and “HyperTrack” libraries.

@import HyperTrack;

[HyperTrack initialize:@"YOUR_PUBLISHABLE_KEY"];

Step 3: Capabilities and permissions

Add background capabilities

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".

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
* Privacy - Motion Usage Description
* Privacy - Location Always and When In Use Usage Description
* Privacy - Location When In Use Usage Description

Configure Location & Motion usage permissions

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

HyperTrack.requestAlwaysAuthorization()
HyperTrack.requestMotionAuthorization()
[HyperTrack requestAlwaysAuthorization];
[HyperTrack requestMotionAuthorization];

Step 4: 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.getOrCreateUser(name, _phone: phoneNumber, lookupID) { (user, error) in
  if (error != nil) {
    // Handle getOrCreateUser API error here
    ...
    return
  }

  if (user != nil) {
    // Handle getOrCreateUser API success here
    ...
  }
}
[HyperTrack getOrCreateUser:name _phone:phoneNumber :lookupId 
    completionHandler:^(HyperTrackUser * _Nullable user, HyperTrackError * _Nullable error) {
  if (user) {
  // Handle createUser success here, if required
  // HyperTrack SDK auto-configures UserId on createUser API call,
  // so no need to call [HyperTrack setUserId:@"USER_ID"] API

  // On UserLogin success
  [self onUserLoginSuccess];

  } else {
    // Handle createUser error here, if required
    ...
  }
}];

Step 5: 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 6: 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.

[success] SDK Setup Completed

Now that we have the basic integration complete, we need to implement the device-server communication.

Stop the SDK

To stop tracking the user, use the stopTracking method.

HyperTrack.stopTracking()
[HyperTrack stopTracking];

Simulate a trip for testing

To simulate a trip, replace startTracking API with startMockTracking and stopTracking API with stopMockTracking. This will run a simulation from your location to a nearby location. You can stop this simulation anytime by calling stopMockTracking API.

results matching ""

    No results matching ""