SDK Methods

Listeners

You can also get the current status of listeners with the below method.

Swift
Objective-C
Swift
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
}
Objective-C
[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

Swift
Objective-C
Swift
class AppDelegate: UIResponder,UIApplicationDelegate,GeoSparkDelegate{
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey:
Any]?) -> Bool {
GeoSpark.initialize("YOUR SDK KEY GOES HERE")
GeoSpark.delegate = self
return 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
}
}
Objective-C
- (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
}

Toggle Event Flags

To listen to events on the server-side, you should enable events for the user using the below method.

Swift
Objective-C
Swift
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
}
Objective-C
[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
}];

Trips

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.

Swift
Objective-C
Swift
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
}
Objective-C
[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.

Swift
Objective-C
Swift
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
 }
Objective-C
[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.

Swift
Objective-C
Swift
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
 }
Objective-C
[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.

Swift
Objective-C
Swift
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
 }
Objective-C
[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.

Swift
Objective-C
Swift
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
}
Objective-C
[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.

Swift
Objective-C
Swift
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
}
Objective-C
[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.

Swift
Objective-C
Swift
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
}
Objective-C
[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.

Swift
Objective-C
Swift
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
}
Objective-C
[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 Trip Status

Subscribe to tripStatus using tripId to get real time trip status.

Swift
Objective-C
Swift
//subscribe to trip status
GeoSpark.subscribeTripStatus("GeoSpark Trip ID")
Objective-C
//subscribe to trip status
[GeoSpark subscribeTripStatus:@"GeoSpark Trip ID")

To stop receiving trip status updates, use the below method.

Swift
Objective-C
Swift
//unsubscribe to trip status
GeoSpark.unSubscribeTripStatus("GeoSpark Trip ID")
Objective-C
//unsubscribe to trip status
[GeoSpark unSubscribeTripStatus:@"GeoSpark Trip ID")