Subscribe Trip (iOS)

Explore how to subscribe to a trip on iOS with Trips v2.

For you to subscribe to a trip, you need to pass the tripID with the Roam.subscribeTrip("tripId") method.

Roam.subscribeTrip("tripId")

Once you subscribe to the trip, you will receive real time trip data in the listener methods

In order to subscribe to the trips with the listener method, you need to make sure the below is implemented.

To listen to location updates, create a class that implements RoamDeleagate and then call Roam.delegate.

Set your RoamDelegate in a code path that will be initialized and executed in the background. For example, ensure that your AppDelegate and not the ViewController implements RoamDelegate. The reason being, AppDelegate will be initialized in the background, whereas a ViewController may not be.

Note: For tracking without user sessions, i.e., self tracking, you can only listen to location, errors and offline trip status data since the locations are not being sent to our servers for event processing.

import UIKit
import Roam
import CoreLocation

@main
class AppDelegate: UIResponder, UIApplicationDelegate, RoamDelegate {
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        Roam.delegate = self
        Roam.initialize("YOUR-SDK-KEY-GOES-HERE")
        return true
    }
    func didUpdateLocation(_ location: RoamLocation) {
        // Do something with the user location
        // location.userId
        // location.activity 
        // location.timezoneOffset  
        // location.recordedAt  
        // location.batteryRemaining
        // location.networkStatus 
        // location.metaData 
        // location.location.speed 
        // location.location.horizontalAccuracy
        // location.location.verticalAccuracy 
        // location.location.altitude  
        // location.location.course       
        // location.location.coordinate.latitude
        // location.location.coordinate.longitude 
    }
    func onReceiveTrip(_ response: RoamTripStatus) {
        // Access subscribeTrip response
    }

You can access the subscribed trip response parameters below:

You can unsubscribe from trips using the tripID.

Roam.unsubscribeTrip("tripId")

Last updated