Build Order Tracking in iOS

In this guide, we will setup the HyperTrack SDK in your iOS app, and call trackAction method to live track an order within your app.

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
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.0'
      end
    end
  end
end

[info] Minimum Deployment target

HyperTrack SDK support iOS 8.0 and above as deployment targets.

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("YOUR_PUBLISHABLE_KEY")
@import HyperTrack;

[HyperTrack initialize:@"YOUR_PUBLISHABLE_KEY"];

Step 3: Setup View Controller

  • Firstly, initialize HyperTrack Map instance and embed this in your view.

  • Secondly, if you want to get callback on various events which happen on HyperTrack map, add HTViewInteractionDelegate extension to your view controller and set it using hyperTrackMap.setHTViewInteractionDelegate API.

    Refer here for more details on view interaction APIs.

  • Optionally, if you want to enable customizations for UI elements, add HTViewCustomizationDelegate extension to your view controller. Once this is done you can implement customization methods to conform to your app's theme and set it using hyperTrackMap.setHTViewCustomizationDelegate API.

    Refer here for more details on customization APIs.

  • Optionally, if you want to get events or updates for tracked Actions, add HTEventsDelegate extension to your view controller. Once this is done you can implement events and updates methods and set it using HyperTrack.setHTEventsDelegate API.

    Refer here for more details on events and updates APIs.

[info] Handle Back Button click

In order to handle back button click, didTapBackButton API needs to be implemented as depicted in the code snippet.

class MapViewController: UIViewController, HTViewInteractionDelegate, 
    HTViewCustomizationDelegate, HTEventsDelegate {
  override func viewDidLoad() {
    super.viewDidLoad()

    ...

    // Instantiate HyperTrack map view and embed this in your view
    let hyperTrackMap = HyperTrack.map()

    // Configure view interaction delegate in HyperTrack map
    hyperTrackMap.setHTViewInteractionDelegate(interactionDelegate: self)

    // Configure view customization delegate in HyperTrack map
    hyperTrackMap.setHTViewCustomizationDelegate(customizationDelegate: self)

    // Configure events delegate in HyperTrack map
    HyperTrack.setEventsDelegate(eventDelegate: self)

    ...
  }

  // Handle back button tap
  func didTapBackButton(_ sender: Any) {
    self.dismiss(animated: true, completion: nil)
  }
}
@interface MapViewController() <HTViewCustomizationDelegate, HTViewInteractionDelegate, HTEventsDelegate>
@property (weak, nonatomic) IBOutlet UIView *hyperTrackView;

@end

@implementation MapViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    ...

    // Instantiate HyperTrack map view and embed this in your view
    HTMap * map = [HyperTrack map];

    // Configure view interaction delegate in HyperTrack map
    [map setHTViewInteractionDelegateWithInteractionDelegate:self];

    // Configure view customization delegate in HyperTrack map
    [map setHTViewCustomizationDelegateWithCustomizationDelegate:self];

    // Configure events delegate in HyperTrack map
    [HyperTrack setEventsDelegateWithEventDelegate:self];

    ...
}

// Handle back button tap
- (void)didTapBackButton:(id _Nonnull)sender{
    [self dismissViewControllerAnimated:true completion:nil];
}

@end

Step 4: Embed HyperTrack view in your ViewController

Add a UIView where the HyperTrack Map view will be embedded.

[info] For Full screen HyperTrack map view

In case you want a full screen HyperTrack map view, embed your View controller's view as hyperTrackMap.embedIn(self.view).

class MapViewController: UIViewController, HTViewCustomizationDelegate, 
    HTViewInteractionDelegate, HTEventsDelegate {

  // Add a UIView in the storyboard layout where HyperTrack view 
  // will be embedded
  var hypertrackView: UIView?

  override func viewDidLoad() {
    super.viewDidLoad()

    ...

    // Embed HyperTrack map in your ViewController
    hyperTrackMap.embedIn(self.hyperTrackView)

    ...
  }
}
@interface LogoutController() <HTViewCustomizationDelegate, HTViewInteractionDelegate, HTEventsDelegate>
@property (weak, nonatomic) IBOutlet UIView *hyperTrackView;

@end

@implementation LogoutController

- (void)viewDidLoad {
    [super viewDidLoad];

    ...

    // Embed HyperTrack map in your ViewController
    [map embedIn:self.mapView];

    ...
}

// Handle back button tap
- (void)didTapBackButton:(id _Nonnull)sender{
    [self dismissViewControllerAnimated:true completion:nil];
}

@end

Step 4: Track Actions

Call the trackAction method with the Action Id that you want to track.

import HyperTrack

HyperTrack.trackActionFor(actionID: <ACTION_ID_HERE>) { (action, error) in
    if (error != nil) {
        // Handle trackActionForActionID API error here
        print("Error in trackOrder: \(error)")
    } else {
        // Handle trackActionForActionID API success here
        print("trackAction for Action ID successful")
    }
}
@import HyperTrack;

[HyperTrack trackActionForActionID:<ACTION_ID_HERE> completionHandler:^(HyperTrackAction *  action , HyperTrackError * error) {
    if (error != nil) {
        // Handle trackActionForActionID API error here
        NSLog(@"Error in trackOrder: %@", error.debugDescription);
    } else {
        // Handle trackActionForActionID API success here
        NSLog(@"trackAction for Action ID successful");
    }
}];

[success] Live Tracking View integration completed

We have the tracking experience successfully integrated now and you are ready to deploy it in production.

Step 5: Test your integration using a demo action

Creates a demo action which is simulated on the HyperTrack Server for you to test your live tracking view.

This API returns an Action object which can be used in trackAction API.

curl -H "Authorization: token YOUR_PK_TOKEN" \
     -H "Content-Type: application/json" \
     -X GET \
     api.hypertrack.com/api/v1/actions/demo/

Step 6: Remove actions

Call removeActions method to remove a list of Action Ids from HyperTrack SDK's live order tracking view.

import HyperTrack

HyperTrack.removeActions();
@import HyperTrack;

[HyperTrack removeActions:nil];

Step 7: Sample Reference

Check out our open-sourced live tracking view (swift) and live tracking view (objc) repositories for detailed reference.

results matching ""

    No results matching ""