You can also get the current status of listeners with the below method.
GeoSpark.getListenerStatus({ (geosparkUser, error) in// access location lister status with geosparkUser?.locationListener// access events lister status geosparkUser?.eventListener// access geospark error code with error?.code// access geospark error message with error?.message}
[GeoSpark getListenerStatusWithHandler:^(GeoSparkUser * user , GeoSparkError * error) {// access location lister status with geosparkUser?.locationListener// access events lister status geosparkUser?.eventListener// access geospark error code with error?.code// access geospark error message with error?.message}];
To listen to location updates create a class that implements GeoSparkDelegate and then call GeoSpark.delegate.
Set yourGeoSparkDelegate in a code path that will be initialized and executed in the background. For example, make your AppDelegate implement GeoSparkDelegate, not a ViewController. AppDelegate will be initialized in the background, whereas a ViewController may not be
class AppDelegate: UIResponder,UIApplicationDelegate,GeoSparkDelegate{func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey:Any]?) -> Bool {GeoSpark.initialize("YOUR SDK KEY GOES HERE")GeoSpark.delegate = selfreturn true}func didUpdateLocation(_ geospark: GeoSparkLocation) {//receive own location updates here//do something with location data using location}func didReceiveUserLocation(_ location:GeoSparkLocationReceived) {//receive other user's location updates here}func didReceiveEvent(_ events:GeoSparkEvents) {//receive user's events updates here}func didReceiveTripStatus(_ tripStatus: TripStatusListener) {//do something with trip status data}}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {// Override point for customization after application launch.[GeoSpark setDelegate:self];return YES;}- (void)didUpdateLocation:(GeoSparkLocation *)location{//receive own location updates here//do something with location data using location}- (void)didReceiveEvents:(GeoSparkEvents *)events{//receive user's events updates here}- (void)didReceiveUserLocation:(GeoSparkLocationReceived *)location{//receive other user's location updates here}- (void)didReceiveTripStatus:(TripStatusListener *)tripStatus{//do something with trip status data}
To listen to events on the server-side, you should enable events for the user using the below method.
GeoSpark.toggleEvents(Geofence: true, Location: true, Trips: true, MovingGeofence: true { (GeoSparkUser, error) in// access location events status with geosparkUser?.locationEvents// access geofence events status with geosparkUser?.geofenceEvents// access trips events status with geosparkUser?.tripsEvents// access moving geofence events status with geosparkUser?.movingGeofenceEvents// access geospark error code with error?.code// access geospark error message with error?.message}
[GeoSpark toggleEventsWithGeofence:true Trip:true Location:true MovingGeofence:true handler:^(GeoSparkUser * user, GeoSparkError * error) {// access location events status with geosparkUser?.locationEvents// access geofence events status with geosparkUser?.geofenceEvents// access trips events status with geosparkUser?.tripsEvents// access moving geofence events status with geosparkUser?.movingGeofenceEvents// access geospark error code with error?.code// access geospark error message with error?.message}];
Use the below code to create a trip directly from the SDK. Set Boolean value true
to create offline trip and false
to create online trip.
GeoSpark.createTrip(Bool, nil) { (trip, error) in// access geospark trip created timestamp with geosparkTrip?.createdAt// access geospark trip user id with geosparkTrip?.userId// access geospark trip id with geosparkTrip?.tripId// access geospark error code with error?.code// access geospark error message with error?.message}
[GeoSpark createTrip:true :nil handler:^(GeoSparkCreateTrip * trip, GeoSparkError * error) {// access geospark trip created timestamp with geosparkTrip?.createdAt// access geospark trip user id with geosparkTrip?.userId// access geospark trip id with geosparkTrip?.tripId// access geospark error code with error?.code// access geospark error message with error?.message}];
To get the trip details.
GeoSpark.getTripDetails("GEOSPARK-TRIP-ID") { (geosparkTrip, error) in// access geospark trip created timestamp with geosparkTrip?.createdAt// access geospark trip user id with geosparkTrip?.userId// access geospark trip id with geosparkTrip?.tripId// access geospark error code with error?.code// access geospark error message with error?.message}
[GeoSpark getTripDetails:@"GEOSPARK-TRIP-ID" handler:^(GeoSparkGetTrip * trip, GeoSparkError * error) {// access geospark trip created timestamp with geosparkTrip?.createdAt// access geospark trip user id with geosparkTrip?.userId// access geospark trip id with geosparkTrip?.tripId// access geospark error code with error?.code// access geospark error message with error?.message}];
To get the trip status.
GeoSpark.getTripStatus("GEOSPARK-TRIP-ID") { (geosparkTrip, error) in// access geospark trip distance covered with geosparkTrip?.distance// access geospark trip speed with geosparkTrip?.speed// access geospark trip duration with geosparkTrip?.duration// access geospark trip id with geosparkTrip?.tripId// access geospark trip started timestamp with geosparkTrip?.startedAt// access geospark error code with error?.code// access geospark error message with error?.message}
[GeoSpark getTripStatus:@"GEOSPARK-TRIP-ID" handler:^(GeoSparkTripListener * geosparkTrip, GeoSparkError * error) {// access geospark trip distance covered with geosparkTrip?.distance// access geospark trip speed with geosparkTrip?.speed// access geospark trip duration with geosparkTrip?.duration// access geospark trip id with geosparkTrip?.tripId// access geospark trip started timestamp with geosparkTrip?.startedAt// access geospark error code with error?.code// access geospark error message with error?.message}];
To get the trip summary.
GeoSpark.getTripSummary("GEOSPARK-TRIP-ID") { (geosparkTrip, error) in// access geospark trip distance covered with geosparkTrip?.distanceCovered// access geospark trip route with geosparkTrip?.route// access geospark trip duration with geosparkTrip?.duration// access geospark trip id with geosparkTrip?.tripId// access geospark error code with error?.code// access geospark error message with error?.message}
[GeoSpark getTripSummary:@"GEOSPARK-TRIP-ID" handler:^(GeoSparkTripSummary * geosparkTrip, GeoSparkError * error) {// access geospark trip distance covered with geosparkTrip?.distanceCovered// access geospark trip route with geosparkTrip?.route// access geospark trip duration with geosparkTrip?.duration// access geospark trip id with geosparkTrip?.tripId// access geospark error code with error?.code// access geospark error message with error?.message}];
To start the trip with the previously created trip id.
GeoSpark.startTrip("GEOSPARK-TRIP-ID") { (status, error) in// access geospark trip status with status// access geospark error code with error?.code// access geospark error message with error?.message}
[GeoSpark startTrip:@"GEOSPARK-TRIP-ID" :@"GEOSPARK-TRIP-DESC" handler:^(NSString * status, GeoSparkError * error) {// access geospark trip status with status// access geospark error code with error?.code// access geospark error message with error?.message}];
To pause the trip with the previously started trip id.
GeoSpark.pauseTrip("GEOSPARK-TRIP-ID") { (status, error) in// access geospark trip status with status// access geospark error code with error?.code// access geospark error message with error?.message}
[GeoSpark pauseTrip:@"GEOSPARK-TRIP-ID" handler:^(NSString * status, GeoSparkError * error) {// access geospark trip status with status// access geospark error code with error?.code// access geospark error message with error?.message}];
To resume the trip.
GeoSpark.resumeTrip("GEOSPARK-TRIP-ID") { (status, error) in// access geospark trip status with status// access geospark error code with error?.code// access geospark error message with error?.message}
[GeoSpark resumeTrip:@"GEOSPARK-TRIP-ID" handler:^(NSString * status, GeoSparkError * error) {// access geospark trip status with status// access geospark error code with error?.code// access geospark error message with error?.message}];
To stop the trip.
GeoSpark.stopTrip("GEOSPARK-TRIP-ID") { (status, error) in// access geospark trip status with status// access geospark error code with error?.code// access geospark error message with error?.message}
[GeoSpark stopTrip:@"GEOSPARK-TRIP-ID" handler:^(NSString * status, GeoSparkError * error) {// access geospark trip status with status// access geospark error code with error?.code// access geospark error message with error?.message}];
Subscribe to tripStatus using tripId to get real time trip status.
//subscribe to trip statusGeoSpark.subscribeTripStatus("GeoSpark Trip ID")
//subscribe to trip status[GeoSpark subscribeTripStatus:@"GeoSpark Trip ID")
To stop receiving trip status updates, use the below method.
//unsubscribe to trip statusGeoSpark.unSubscribeTripStatus("GeoSpark Trip ID")
//unsubscribe to trip status[GeoSpark unSubscribeTripStatus:@"GeoSpark Trip ID")