iOS Quickstart Guide

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

Step 1: Install SDK

Thereb are two methods by which GeoSpark iOS SDK can be used. You can install it with CocoaPods or manually (install it by including the SDK source code in your Xcode project).

Option A - Install using CocoaPods (Recommended)

Add the GeoSpark SDK to your Podfile as shown below.

Text

                                  
                                      
  pod 'GeoSpark'
                              
                              

Once you have updated your Podfile run pod install in your terminal to automatically download and install the SDK in your project.

Option B - Manual Install

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.

Step 2: Configure project

To track the user's location in the foreground, background , you must add the below string key in your Info.plist

Text

                                  
                                    
 Privacy - Location Always Usage Description
 Privacy - Location Always and When In Use Usage Description
 Privacy - Location When In Use Usage Description
 Privacy - Motion Usage Description
                              
                              

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

Step 3: SDK Integration

Import GeoSpark into your AppDelegate file.

                                
  import GeoSpark
  #import < GeoSpark/GeoSpark.h >
                               
                            

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

                                
  func application(_ application: UIApplication,
  didFinishLaunchingWithOptions launchOptions:
  [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
      GeoSpark.intialize("PUBLISHABLEKEY")
          return true
    }
  - (BOOL)application:(UIApplication *)application
  didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
       [GeoSpark intialize:@"PUBLISHABLEKEY"];
       return YES;
  }
                               
                            

Step 4: APNS Configurations

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

                                
  func application(_ application: UIApplication,
  didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
        GeoSpark.setDeviceToken(deviceToken)
   }
  - (void)application:(UIApplication *)application
  didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken{
      [GeoSpark setDeviceToken:deviceToken];
    }
                               
                               
                            

Step 5: Check and request permission

Before tracking the user's location, the user must have authorized location permission and motion permission for the app.

                                
  // Request for location permission
     GeoSpark.requestLocation()
  // Request for motion Permission
     GeoSpark.requestLocation()
  // Check location permission is enable or not
     GeoSpark.isLocationEnabled()
  // Check motion permission is enable or not
     GeoSpark.isMotionEnabled()
  // Request for location permission
     [GeoSpark requestLocation];
  // Request for motion Permission
     [GeoSpark requestMotion];
  // Check location permission is enable or not
     [GeoSpark isLocationEnabled];
  // Check motion permission is enable or not
     [GeoSpark isMotionEnabled];  
                               
                            

Step 6: User

Create User

The SDK needs a User ID object to identify the device. Before creating user you should have a device token as creating user without device token is not possible.

                                
  GeoSpark.createUser({ (user) in
      // user.userId
     },onFailure: { (error) in
             // error.errorCode
             // error.errorMessage
    })
  [GeoSpark createUser:^(GeoSparkUser * user) {
          // user.userId
      } onFailure:^(GeoSparkError * error) {
             // error.errorCode
             // error.errorMessage
    }];
                               
                            

Get User

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

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

Set Description (Optional)

You can set Description for user by using setDescription()method.

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

Step 7: Location

Start Location Tracking

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

                                
  GeoSpark.startTracking()
  [GeoSpark startTracking];
                               
                            

Step 8: Logout User

User can be logged out by using logout() method.

                                
  GeoSpark.logout({ (message) in
      // message
   }) { (error) in
         // error.errorCode
        // error.errorMessage
  }
  [GeoSpark logout:^(NSString * message) {
            // message
  } onFailure:^(GeoSparkError * error) {
         // error.errorCode
        // error.errorMessage
  }];