#iOS

Integrate our SDK in your iOS app.

#Quick Start

GeoSpark provides an iOS SDK that enables App developers to track location, geofence and trips.


#Step 1: Install SDK

Install using Cocoapods, open podfile add SDK to file.

Once you have updated your Podfile, run pod install in your terminal.

Import GeoSpark into your AppDelegate file.


pod 'GeoSpark' 

//Swift
import GeoSpark

//Objective-C
#import <GeoSpark/GeoSpark.h />

#Step 2: Configure Project

To configure the location services, add following entries to the Info.plist file.

Then, in your project settings, go to Capabilities > Background Modes and turn on background fetch, location updates, remote-notifications.

#Step 3: Initialize SDK

Initialize the SDK in your AppDelegate class before calling any other GeoSpark methods under this application:didFinishLaunchingWithOptions:

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

//Objective-C
- (BOOL)application:(UIApplication *)application 
  didFinishLaunchingWithOptions:(NSDictionary *)
  launchOptions {
    [GeoSpark intialize:@"PUBLISHABLEKEY"];
    return YES;
}        

#Step 4: Create User

The 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
GeoSpark.createUser("User Description",{ (user) in
    // user.userId
  },onFailure: { (error) in
    // error.errorCode
    // error.errorMessage
})

//Objective-C
[GeoSpark createUser:@"User Description" 
 :^(GeoSparkUser * user) {
    // user.userId
  } onFailure:^(GeoSparkError * error) {
    // error.errorCode
    // error.errorMessage
}];

#Step 5: Start Location Tracking

To start tracking the location.

//Swift
// To enable motion and location, 
//call requestMotion and requestLocation methods.
if GeoSpark.isMotionEnabled() == false {
    GeoSpark.requestMotion()
} else if GeoSpark.isLocationEnabled() == false{
    GeoSpark.requestLocation()
} else {
    GeoSpark.startTracking()
}

 //Objective-C
if ([GeoSpark isMotionEnabled] == false) {
  [GeoSpark requestMotion];
} else if ([GeoSpark isLocationEnabled] == false){
  [GeoSpark requestLocation];
} else {
  [GeoSpark startTracking];
}

#Utility Methods

#Initialize SDK

Initialize the SDK in your AppDelegate

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

//Objective-C
- (BOOL)application:(UIApplication *)application 
  didFinishLaunchingWithOptions:(NSDictionary *)
  launchOptions {
    [GeoSpark intialize:@"PUBLISHABLEKEY"];
      return YES;
  }

#Set DeviceToken

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

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

//Objective-C
- (void)application:(UIApplication *)application 
  didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)
  deviceToken{
    [GeoSpark didRegisterForRemoteNotificationsWithDeviceToken: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
GeoSpark.createUser("User Description",{ (user) in
    // user.userId
},onFailure: { (error) in
    // error.errorCode
    // error.errorMessage
  })

//Objective-C
[GeoSpark createUser:@"User Description" 
  :^(GeoSparkUser * user) {
    // user.userId
} onFailure:^(GeoSparkError * error) {
    // 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
GeoSpark.getUser("USER_ID", { (user) in
  // user.userId
},onFailure: { (error) in  
      // error.errorCode
      // error.errorMessage
  })

//Objective-C
[GeoSpark getUser:@"USER_ID" :^(GeoSparkUser * user) {
  // user.userId
} onFailure:^(GeoSparkError * error) {
      // error.errorCode
     // error.errorMessage
  }];  

#User Description

You can set Description for user by using setDescription method.

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

//Objective-C
[GeoSpark setDescription:@"Description" :^(GeoSparkUser * user) {
  // user
} onFailure:^(GeoSparkError * error) {
    // error.errorCode
    // error.errorMessage
  }];  

#Set Events

Use this method after user creation to enable user events for geofence, activity and trips. By default, all user events will be disabled post user creation.

//Swift
GeoSpark.toggleEvents(Geofence: Bool, Trip: Bool, Activity: Bool, { (events)
  in
            // events.geofenceEvents
           // events.activityEvents
          // events.tripsEvents
}) { (error) in
           //error.errorCode
          //error.errorMessage
    }              

//Objective-C
[GeoSpark toggleEventsWithGeofence:true Trip:true Activity:true
:^(GeoSparkEvents * events) {
        // events.geofenceEvents
       // events.activityEvents
      // events.tripsEvents
} onFailure:^(GeoSparkError * error) {
            //error.errorCode
           //error.errorMessage
  }];

#Get Events

Use this method after user creation to get the current status of user events for geofence, activity and trips.

//Swift
GeoSpark.getEventsStatus({ (events) in
       // events.geofenceEvents
      // events.activityEvents
     // events.tripsEvents
})  { (error) in
         //error.errorCode
        //error.errorMessage
    }

//Objective-C
[GeoSpark getEventsStatus:^(GeoSparkEvents * events) {
        // events.geofenceEvents
       // events.activityEvents
      // events.tripsEvents
} onFailure:^(GeoSparkError * error) {
        //error.errorCode
       //error.errorMessage
  }];    

#Check Location Permission

Check whether your App has location permission.

//Swift
GeoSpark.isLocationEnabled()

//Objective-C
[GeoSpark isLocationEnabled];

#Check Motion Permission

Check whether your App has motion permission.

//Swift
GeoSpark.isMotionEnabled()

//Objective-C
[GeoSpark isMotionEnabled];

#Request Location Permission

Check whether your App has location permission.

//Swift
GeoSpark.requestLocation()

//Objective-C
[GeoSpark requestLocation];

#Request Motion Permission

Check whether your app has motion permission.

//Swift
GeoSpark.requestMotion()

//Objective-C
[GeoSpark requestMotion];

#Start Location Tracking

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

//Swift
GeoSpark.startTracking()

//Objective-C
[GeoSpark startTracking];

#Check Location Tracking

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

//Swift
GeoSpark.isLocationTracking()

//Objective-C
[GeoSpark isLocationTracking];

#Stop Location Tracking

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

//Swift
GeoSpark.stopTracking()

//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
//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
    }
....
}

//Objective-C
//AppDelegate.h
#import <GeoSpark/GeoSpark.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate,GeoSparkDelegate>

//AppDelegate.m
- (BOOL)application:(UIApplication *)application 
  didFinishLaunchingWithOptions: (NSDictionary *)launchOptions 
  {
    GeoSpark.delegate = self;
    return YES;
  }
....
- (void)didUpdateLocation:(GSLocation *)location {
   //do something with location, user
}

#Current Location

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

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

//Objective-C
[GeoSpark getCurrentLocation:10:^(GSLocation * location) {
  //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).

Note: 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.

//Swift
GeoSpark.updateCurrentLocation(accuracy)

//Objective-C
[GeoSpark updateCurrentLocation:accuracy];

#Start Trip

Once user start tracking location, you can use startTrip method

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

//Objective-C
[GeoSpark startTrip:@"Trip Id":@"Trip Description" :^(GeoSparkTrip * trip) {
  // trip.msg
} onFailure:^(GeoSparkError * error) {
        // error.errorCode
       // error.errorMessage
  }];

#End Trip

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

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

//Objective-C
[GeoSpark endTrip:@"TRIPID" :^(GeoSparkTrip * trip) {
  // trip.msg
} onFailure:^(GeoSparkError * error) {
     // error.errorCode
    // error.errorMessage
}];

#Active Trips

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

//Swift
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
   }

//Objective-C
[GeoSpark activeTrips:^(ActiveTripsV2Response * trip) {
        // 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
} onFailure:^(GeoSparkError * error) {
        // error.errorCode
        // error.errorMessage
  }];

#TrackLocationInAppState

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

Parameter Description
SETTINGS GSAppState.AlwaysOn, GSAppState.Background, GSAppState.Foreground, GSAppState.Terminated
//Swift
GeoSpark.trackLocationInAppState([SETTINGS])

//Objective-C
[GeoSpark trackLocationInAppState:@[SETTINGS]];

#TrackLocationInMotion

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

Parameter Description
SETTINGS GSMotion.All, GSMotion.Stationary, GSMotion.Running, GSMotion.Walking,GSMotion.AutoMotive
//Swift
GeoSpark.trackLocationInMotion([SETTINGS])

//Objective-C
[GeoSpark trackLocationInMotion:@[SETTINGS]];

#setLocationAccuracy

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

//Swift
GeoSpark.setLocationAccuracy(accuracy)

//Objective-C
[GeoSpark setLocationAccuracy:accuracy];

#Notification Opened Handler

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

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

//Objective-C
- (void)userNotificationCenter:(UNUserNotificationCenter *)
center didReceiveNotificationResponse:
(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler
    {
        [GeoSpark notificationOpenedHandler:response];
        completionHandler();
    }

#Logout User

You can logout user by using logoutUser method.

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

//Objective-C
[GeoSpark logoutUser:^(NSString * message) {
       // message
} onFailure:^(GeoSparkError * error) {
      // error.errorCode
      // error.errorMessage
  }];

#Troubleshooting

Analyse & resolve your issues.


#Requirements

  • iOS Version 10.0 and above

#Install SDK Manual

Download and unzip the GeoSpark SDK.

Add the GeoSpark SDK to your Xcode Project by dragging the file into your Project Navigator.

You can do this by selecting the project file in the navigator on the left side of the Xcode window, and then navigating to the Linked Frameworks and Libraries section. From there, click the + button to add the GeoSpark frameworks.

#Changelog

Keep yourself updated.


#v2.1.1 - (Sep 05, 2019)

Added

  • New utility methods for user events.

#v2.0.0 - (June 28, 2019)

Added

  • New utility method Notification Opened Handler.

Modified

  • Redesigns the SDK under the hood to maximize reliability, efficiency, and making integration simple.

#v1.9.2 - (June 11, 2019)

Added

  • Support for Swift 5.

#v1.9.1 - (May 06, 2019)

Added

  • Update SDK Method for Trips V2.

#v1.9 - (March 28, 2019)

Added

  • New utility method to update user's current location.
  • New utility method to check if location tracking is started.

#v1.8 - (February 27, 2019)

Fixed

  • Improved location tracking.
  • Better stationary point update with high accuracy.

#v1.7.1 - (January 31, 2019)

Added

  • New utility method to get user's current location.

Modified

  • None

Fixed

  • Improved location tracking.

#v1.7 - (January 31, 2019)

Added

  • New utility method to get user's current location.

Modified

  • None

Fixed

  • Improved location tracking.

#v1.6 - (January 4, 2019)

Modified

  • Updated Description for create user.
  • Minor technical enhancements.

#v1.5 - (December 5, 2018)

Modified

  • Minor technical enhancements.

#v1.4 - (December 5, 2018)

Modified

  • Minor and major technical enhancements.

#v1.3 - (December 5, 2018)

Fixed

  • Minor and major bug fixes.

#v1.2 - (December 3, 2018)

Added

  • Added DeleteGeofence method.
  • Added Logout method.
  • Added SetDescription method.

Fixed

  • Minor and major bug fixes.

#v1.1 - (November 20, 2018)

Fixed

  • Critical bug fixes.

#v1.0 -(October 31, 2018)

Offline Location Updates Method

  • We reliably track location offline and upload to server whenever connection is established back to internet. This feature helps to provide seamless tracking irrespective of internet connectivity issues.

Trips

  • Manage trips through SDK using 'Start Trip' & 'End Trip'.
  • Also track your trips as well using trip routes.

Geofence

  • Using SDK can create personalized geofence & get those geofence list.