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 9.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.requestAlwaysLocationAuthorization { (authorized) in
  //handle authorization status, if needed
}
HyperTrack.requestMotionAuthorization()
[HyperTrack requestAlwaysLocationAuthorizationWithCompletionHandler:^(BOOL authorized) {
  //handle authorization status, if needed
}];
[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.

HyperTrack.getOrCreateUser(name: name, phone: phone, uniqueId: phone) { (user, error) in
  if (error != nil) {
    // Handle getOrCreateUser API error here
    ...
    return
  }

  if (user != nil) {
    // Handle getOrCreateUser API success here
    ...
  }
}
[HyperTrack getOrCreateUserWithName:name phone:phone uniqueId:uniqueId 
  completionHandler:^(HTUser * _Nullable user, HTError * _Nullable error) {
  if (user) {
  // Handle getOrCreateUser API success here
    ...
  } else {
    // Handle createUser error here, if required
    ...
  }
}];

Step 5: Resume Tracking

Tracking is automatically started if there is atleast one action assigned to the user. You can force pause tracking by calling pauseTracking method in which case tracking won't be resumed even after assigning an action to the user. To resume the force paused tracking use resumeTracking method. Tracking will be started as soon as an action is assigned to the user.

HyperTrack.resumeTracking()
[HyperTrack resumeTracking];

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.

Pause Tracking

Tracking is automatically started if there is atleast one action assigned to the user. You can force pause tracking by calling pauseTracking method in which case tracking won't be resumed even after assigning an action to the user.

HyperTrack.pauseTracking()
[HyperTrack pauseTracking];

results matching ""

    No results matching ""