Utility Methods

OW
Last updated 20 days ago

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
}

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()

Stop Location Tracking

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

Swift
Objective-C
GeoSpark.stopTracking()

Location listener

Implement GeoSparkDelegate in AppDelegate , that will be initialized and executed in the background.

Swift
Objective-C
GeoSpark.delegate = self

Current Location

Get current location of the user.

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

Start Trip

Once user start tracking location, you can use startTrip method

Swift
Objective-C
GeoSpark.startTrip("Trip Description", { (trip) in
// Trip id , start time
// trip.tripId
//trip.trip_started_at
}, 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 id , ended time
// trip.tripId
// trip.trip_ended_at
}, 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({ (trips) in
// List of tripid, started time
// trips.data[0].tripId
// trips.data[0].tripStartedAt
}, onFailure: { (error) in
// error.errorCode
// error.errorMessage
})

Create Geofence

Using the parameters latitude, longitude, expiry time, radius one can create geofences from SDK.

Make sure radius should be (50 -1000 meters) and set expiry time less than 24hrs.

Swift
Objective-C
GeoSpark.createGeofence(latitude: latitude, longitude: logitude, expiry: expiry, radius: radius, { (geofence) in
// geofence.create_at
// geofence.expire_at
// geofence.geofence_id
// geofence.geometry_radius
// geofence.coordinate
}, onFailure: { (error) in
// error.errorCode
// error.errorMessage
})

Geofence List

You can see the list of geofences created by user using geofenceListmethod.

Swift
Objective-C
GeoSpark.geofenceList({ (geofenceLists) in
//geofenceList.data.count
}, onFailure: { (error) in
// error.errorCode
// error.errorMessage
})

Delete Geofence:

You can delete geofence by using deleteGeofence method.

Swift
Objective-C
GeoSpark.deleteGeofence("GEOFENCE_ID", { (message) in
// message
}) { (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)

Logout User

You can logout user by using logoutUser method.

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