HERE iOS SDK Developer's Guide

Fleet Connectivity

The Fleet Connectivity features allows applications that use the HERE iOS SDK to receive job dispatches from a fleet dispatcher. Each job dispatch contains custom information, such as a geocoordinate to a destination, that can be used by your application for navigation or other purposes.

Your application, which is known as an asset in a fleet connectivity context, can also use this feature to indicate its job status to the dispatcher. These job statuses include whether it is available to receive a job, whether the job was accepted, and whether the job is finished.

Note: The HERE iOS SDK contains APIs for you to implement a fleet connectivity client. For instructions on how to use the fleet dispatcher features, see the Fleet Connectivity Extension Developer's Guide at developer.here.com.

NMAFleetConnectivityService

This singleton class holds information such as this fleet asset ID, the fleet dispatcher to connect to, the running job, and job event polling interval.

Note: At a minimum, you must set the fleet asset and dispatcher IDs before starting the fleet connectivity service.

NMAFleetConnectivityEvent and NMAFleetConnectivityServiceDelegate

You can set a NMAFleetConnectivityServiceDelegate to the service to listen for dispatcher events. Dispatcher events are highly customizable, with the only mandatory information being a jobID. Otherwise, you can define any type of information in its content payload, such as a set of geocoordinates, a Place ID, or an address string.

There are two methods that need to be implemented in NMAFleetConnectivityServiceDelegate:
  • fleetConnectivityMessageReceived:
  • fleetConnectivityEventAcknowledged:error:

Using the Fleet Connectivity Feature

The basic flow of how to use the Fleet Connectivity feature is as follows:
  1. Start the fleet connectivity service and begin listening for fleet connectivity events.
    NMAFleetConnectivityService *service =
      [NMAFleetConnectivityService sharedFleetConnectivityService];
    service.delegate = self;
    service.dispatcherId = @"Driver-123";
    service.assetId = @"Truck-321";
    if ([service start]) {
      // service started
      self.serviceRunning = YES;
    } else {
      // service failed to start
    }
    
  2. Implement the delegate. Once a message is received, check if it is a dispatch job.
    - (void)fleetConnectivityMessageReceived:(NMAFleetConnectivityMessage *)message
    {
      if (message.message.length > 0) {
        //display the optional message
      }
      if ([message isKindOfClass:[NMAFleetConnectivityJobMessage class]]) {
        //This message represents a job
    
        NMAFleetConnectivityJobMessage *newDestinationMessage =
          (NMAFleetConnectivityJobMessage *)message;
        //Get job ID from newDestinationMessage.jobId
        //Get location (in your preferred format) from newDestinationMessage.message
        //Get threshold from newDestinationMessage.etaThreshold
        //(this threshold controls when ETA updates are sent back to dispatcher)
      } else if ([message isKindOfClass:[NMAFleetConnectivityCustomMessage class]]) {
        //This message does not represent a job
    
        NMAFleetConnectivityCustomMessage *customMessage =
          (NMAFleetConnectivityCustomMessage *)message;
        //get job ID from customMessage.jobId
        //get messages from customMessage.content
      }
    }
    
    
  3. Send an event to the dispatcher that the job has been accepted.
    NMAFleetConnectivityJobStartedEvent *event =
      [[NMAFleetConnectivityJobStartedEvent alloc] init];
    // populate event.jobId
    // populate event.etaThreshold
    if ([[NMAFleetConnectivityService sharedFleetConnectivityService] sendEvent:event]) {
      // job is running
      // for example, your application can begin navigating to the job destination
    } else {
      // job has failed to start
    }
    
    Alternatively, you can also reject the the job by sending a rejection event.
    NMAFleetConnectivityJobRejectedEvent *event =
      [[NMAFleetConnectivityJobRejectedEvent alloc] init];
    // populate event.jobId
    if ([[NMAFleetConnectivityService sharedFleetConnectivityService] sendEvent:event]) {
      // job is rejected
    }
    
  4. While a job is in the accepted state, you can tell the dispatcher that the job is canceled.
    NMAFleetConnectivityJobCancelledEvent *event =
      [[NMAFleetConnectivityJobCancelledEvent alloc] init];
    if (![[NMAFleetConnectivityService sharedFleetConnectivityService] sendEvent:event]) {
      // failed to cancel job
    }
    
  5. Upon job completion, notify the server that the job is finished. For example, you can choose to send this event when your application has successfully finished the navigation session.
    NMAFleetConnectivityJobFinishedEvent *event =
      [[NMAFleetConnectivityJobFinishedEvent alloc] init];
    if (![[NMAFleetConnectivityService sharedFleetConnectivityService] sendEvent:event]) {
      // the job has failed to be finished
    }
    
  6. In the previous steps, after sending an event, you will receive an acknowledgment from the dispatching server through the fleetConnectivityEventAcknowledged:error: callback.
    - (void)fleetConnectivityEventAcknowledged:(NMAFleetConnectivityEvent *)event error:(NMAFleetConnectivityError *)error
    {
      if ([event isKindOfClass:[NMAFleetConnectivityJobStartedEvent class]]) {
        // the job start event is acknowledged
      } else if ([event isKindOfClass:[NMAFleetConnectivityJobRejectedEvent class]]) {
        // the job rejection event is acknowledged
      } else if ([event isKindOfClass:[NMAFleetConnectivityJobFinishedEvent class]]) {
        // the job completion event is acknowledged
      } else if ([event isKindOfClass:[NMAFleetConnectivityJobCancelledEvent class]]) {
        // the job cancellation event is acknowledged
      } else if ([event isKindOfClass:[NMAFleetConnectivityCustomEvent class]]) {
        // the custom event is acknowledged
      }
    }
    
  7. Stop the service by calling [[NMAFleetConnectivityService sharedFleetConnectivityService] stop];