Utility Methods

An archive of our SDK methods.

Initialize SDK

Initialize the SDK in your AppDelegate

Swift
Objective-C
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
GeoSpark.intialize("PUBLISHABLEKEY")
return true
}

Set DeviceToken

GeoSpark SDK is capable of sending push notifications to your users. Check here to get device token.

Swift
Objective-C
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
GeoSpark.setDeviceToken(deviceToken)
}

Create User

GeoSpark SDK needs an User ID object to identify the device. Before creating user you should have device token as you cannot create user without device token.

Swift
Objective-C
GeoSpark.createUser("User Description",{ (user) in
// user.userId
},onFailure: { (error) in
// error.errorCode
// error.errorMessage
})

Get User

If you already have an User ID, then SDK has a convenience method getUser() to start the session for the existing user.

Swift
Objective-C
GeoSpark.getUser("USER_ID", { (user) in
// user.userId
},onFailure: { (error) in
// error.errorCode
// error.errorMessage
})

User Description

You can set Description for user by using setDescription method.

Swift
Objective-C
GeoSpark.setDescription("Description", { (user) in
// user
}, onFailure: { (erorr) in
// error.errorCode
// error.errorMessage
})

Check Location Permission

Check whether your App has location permission.

Swift
Objective-C
GeoSpark.isLocationEnabled()

Check Motion Permission

Check whether your App has motion permission.

Swift
Objective-C
GeoSpark.isMotionEnabled()

Request Location Permission

Check whether your App has location permission.

Swift
Objective-C
GeoSpark.requestLocation()

Request Motion Permission

Check whether your app has motion permission.

Swift
Objective-C
GeoSpark.requestMotion()

Start Location Tracking

You can start tracking the user location by using startTracking() method.

Swift
Objective-C
GeoSpark.startTracking()

Check Location Tracking

Check whether location tracking is started or not. This method returns boolean value.

Swift
Objective-C
GeoSpark.isLocationTracking()

Stop Location Tracking

You can stop tracking the user location by using stopTracking() method.

Swift
Objective-C
GeoSpark.stopTracking()

Location listener

To listen for location client-side in the background, create a class that implements GeoSparkDelegate and then call GeoSpark.delegate .

Set your GeoSparkDelegate in a codepath 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
AppDelegate.swift
class AppDelegate: UIResponder,
UIApplicationDelegate,UNUserNotificationCenterDelegate,GeoSparkDelegate{
var window: UIWindow?
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey:
Any]?) -> Bool {
GeoSpark.delegate = self
return true
}
....
func didUpdateLocation(_ location: GSLocation) {
//do something with location, user
}
....
}
AppDelegate.h
AppDelegate.m
#import <GeoSpark/GeoSpark.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate,GeoSparkDelegate>

Current Location

Get current location of the user. You can set the accuracy from 10 to 100 meters (default is 10).

Swift
Objective-C
GeoSpark.getCurrentLocation(accuracy) { (location) in
//location.latitude
//location.longitude
//location.activity
//location.accuracy
//location.userId
}

Update Current Location

Using updateCurrentLocation method, one can update user current location, you can set the accuracy from 10 to 100 meters (default is 10).

Swift
Objective-C
GeoSpark.updateCurrentLocation(accuracy)

This method should be used only if you need to update the current location of the device with better accuracy. Using this method often might consume battery.

Start Trip

Once user start tracking location, you can use startTrip method

Swift
Objective-C
GeoSpark.startTrip("Trip Id","Trip Description", { (trip) in
// trip.msg
}, onFailure: { (error) in
// error.errorCode
// error.errorMessage
})

End Trip

Once the trip started, you can stop the trip using TRIPID

Swift
Objective-C
GeoSpark.endTrip("TRIPID", { (trip) in
// trip.msg
}, onFailure: { (error) in
// error.errorCode
// error.errorMessage
})

Active Trips

By using activeTrips method you can see active trips of the user.

Swift
Objective-C
GeoSpark.activeTrips({ (trip) in
// trip.trips[0].trip_id
// trip.trips[0].isDeleted
// trip.trips[0].isEnded
// trip.trips[0].isStarted
// trip.trips[0].createdAt
// trip.trips[0].updatedAt
}) { (error) in
// error.errorCode
// error.errorMessage
}

TrackLocationInAppState

Using trackLocationInAppState method, one can configure the SDK settings for enabling location tracking during given App states.

Swift
Objective-C
GeoSpark.trackLocationInAppState([SETTINGS])
‚Äč

Parameter

Description

SETTINGS

GSAppState.AlwaysOn,GSAppState.Background, GSAppState.Foreground,GSAppState.Terminated

TrackLocationInMotion

Using trackLocationInMotion method, one can configure the SDK settings for enabling motion tracking.

Swift
Objective-C
GeoSpark.trackLocationInMotion([SETTINGS])

Parameter

Description

SETTINGS

GSMotion.All, GSMotion.Stationary, GSMotion.Running, GSMotion.Walking,GSMotion.AutoMotive

setLocationAccuracy

Using setLocationAccuracy method, one can set location tracking with accuracy (5 to 100 meters).

Swift
Objective-C
GeoSpark.setLocationAccuracy(accuracy)

Notification Opened Handler

By using this method inside Notification delegate method, track the campaigns impressions and counts.

Swift
Objective-C
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void)
{
GeoSpark.notificationOpenedHandler(response)
completionHandler()
}

Logout User

You can logout user by using logoutUser method.

Swift
Objective-C
GeoSpark.logoutUser({ (message) in
// message
}) { (error) in
// error.errorCode
// error.errorMessage
}