Using Actions

An Action represents a pickup, delivery, visit or any other transaction event being performed by the User. In this guide, we will cover how to complete actions on the SDK.

Step 1: Start the SDK

To start tracking the user, use the startTracking method.

HyperTrack.startTracking()
[HyperTrack startTracking];

Step 2: Assigning Actions to a User

Create and assign an Action object with the user id to start. You can refer to the Action model for more options.

// Construct a place object for Action's expected place.
// @NOTE: Pass either the address or the location for the expected place.
// Both have been passed here only to show how it can be done, in case
// the data is available.
let expectedPlace: HyperTrackPlace = HyperTrackPlace().setAddress(address:
    "2200 Sand Hill Road, Menlo Park, CA, USA")

// Create ActionParams object specifying the Delivery Type Action parameters including 
// ExpectedPlace, ExpectedAt time and Lookup_id.
let htActionParams = HyperTrackActionParams()
htActionParams.expectedPlace = expectedPlace
htActionParams.type = "delivery"
htActionParams.lookupId = orderID

// Call createAndAssignAction to assign Delivery action to the current
// user configured in the SDK using the Place object created above.
HyperTrack.createAndAssignAction(htActionParams) { action, error in
    if let error = error {
        // Handle createAndAssignAction API error here
        ...
        return
    }

    if let action = action {
        // Handle createAndAssignAction API success here
        ...
    }
}
// Construct a place object for Action's expected place.
// @NOTE: Pass either the address or the location for the expected place.
// Both have been passed here only to show how it can be done, in case
// the data is available.
HyperTrackPlace * expectedPlace = [[HyperTrackPlace alloc] init];
[expectedPlace setAddress:@"2200 Sand Hill Road, Menlo Park, CA, USA"];

// Create ActionParams object specifying the Delivery Type Action parameters including ExpectedPlace,
// ExpectedAt time and Lookup_id.
HyperTrackActionParams * htActionParams = [[HyperTrackActionParams alloc] init];
[htActionParams setExpectedPlace:expectedPlace];
[htActionParams setType:@"delivery"];
[htActionParams setLookupId:orderID];

// Call createAndAssignAction to assign Delivery action to the current
// user configured in the SDK using the Place object created above.
[HyperTrack createAndAssignAction:htActionParams 
                                 :^(HyperTrackAction * _Nullable action,
                                    HyperTrackError * _Nullable error) {
    if (error) {
        // Handle createAndAssignAction API error here
        ...
        return;
    } 

    if (action) {
        // Handle createAndAssignAction API success here
        ...
    }
}];

Step 3: Fetch Action details

Call getAction API to fetch action details for a given action id from HyperTrack Server.

let action = HyperTrack.getAction(self.actionId) { action, error in
    if let error = error {
        print(error)
    }
    if let action = action {
        // Use Action entity properties.
    }
}
[HyperTrack getAction:actionID 
    completionHandler:^(HyperTrackAction * _Nullable action, 
                        HyperTrackError * _Nullable error) {
    if (error) {
        // Handle getAction API error here
        ...
        return;
    } 

    if (action) {
        // Handle getAction API success here
        ...
    }
}];

Step 4: Completing an Action

Call completeAction API to mark an action completed.

HyperTrack.completeAction(self.actionId)
[HyperTrack completeAction:actionID];

Step 5: Stop the SDK

To stop tracking the user, use the stopTracking method.

HyperTrack.stopTracking()
[HyperTrack stopTracking];

results matching ""

    No results matching ""