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 resumeTracking method.

HyperTrack.resumeTracking()
[HyperTrack resumeTracking];

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 = HTPlaceBuilder()
    .setAddress("2200 Sand Hill Road, Menlo Park, CA, USA")
    .setLocation(CLLocationCoordinate2D(latitude: 37.422970, longitude: -122.199225))
    .build()

// Create ActionParams object specifying the Delivery Type Action parameters including 
// expectedPlace, unique_id etc.
let actionParams = HTActionParams()
    .setType(type: "delivery")
    .setExpectedPlace(expectedPlace: expectedPlace)
    .setUniqueId(uniqueId: orderID)

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

    if let action = action {
        // Handle createAction 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.
HTPlace* expectedPlace = [[[[[HTPlaceBuilder alloc] init] 
    setAddress:@"2200 Sand Hill Road, Menlo Park, CA, USA"] 
    setLocation:CLLocationCoordinate2DMake(37.422970, -122.199225)] 
    build];
// Create ActionParams object specifying the Delivery Type Action parameters including
// expectedPlace, unique_id etc.
HTActionParams* actionParams = [[HTActionParams alloc] init];
[actionParams setExpectedPlace:expectedPlace];
[actionParams setType:@"delivery"];
[actionParams setLookupId:orderID];

// Call createAction to assign Delivery action to the current
// user configured in the SDK using the Place object created above.
[HyperTrack createAction:actionParams :^(HTAction * action, HTError * error) {
    if (error) {
        // Handle createAction API error here
        ...
        return;
    } 

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

Step 3: Fetch Action details

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

HyperTrack.getActionFor(actionId: actionId) { (action, error) in
    if let _ = error {
        // Handle getActionFor API error here
        ...
        return;
    }

    if let _ = action {
        // Handle getActionFor API success here
        ...
    }
}
[HyperTrack getActionForActionId:actionId 
    completionHandler:^(HTAction * _Nullable action, HTError * _Nullable error) {
    if (error) {
        // Handle getActionFor API error here
        ...
        return;
    }

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

Step 4: Completing an Action

Call completeAction API to mark an action completed.

HyperTrack.completeActionInSynch(actionId) { (action, error) in
    if let _ = error {
        // Handle completeActionInSynch API error here
        ...
        return;
    }

    if let _ = action {
        // Handle completeActionInSynch API success here
        ...
    }
}
[HyperTrack completeActionInSynch:actionId completionHandler:^(HTAction * _Nullable action, HTError * _Nullable error) {
    if (error) {
        // Handle completeActionInSynch API error here
        ...
        return;
    }

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

Step 5: Stop the SDK

To stop tracking the user, use the pauseTracking method.

HyperTrack.pauseTracking()
[HyperTrack pauseTracking];

results matching ""

    No results matching ""