SDK for iOS app

Download the iOS Telematics SDK and install it in your environment

Introduction

To utilize our telematics environment in your iOS app, you should integrate the Telematics SDK iOS framework into your app.
While you could manually add the framework, we strongly recommend using the CocoaPods dependency manager. If your project already uses other CocoaPods, continue after this first step:

Adding the SDK to your project

Install CocoaPods

📘

Skip this step, If your project already has CocoaPods

  • open a terminal window in the main project folder
  • run the following commands to install CocoaPods and create a "Podfile":
$ sudo gem install cocoapods
$ pod init

Add the SDK to your Podfile

  • locate 'Podfile' in the main project folder
  • using your preferred text editor, add the following line to your Podfile:
pod 'RaxelPulse'
  • open a terminal window in the main project folder
  • run the following commands in a terminal window to re-evaluate the Podfile, and add the RaxelPulse library to your project
$ pod install

Setting up the SDK

Please check RaxelPulse target in pod Always Embed Swift Standard Libraries: NO

Use this in your project target
Always Embed Swift Standard Libraries: YES

Enable capabilities

Configure the information property list file (Info.plist) with an XML snippet that contains data about your app.
Right-click info.plist, and choose Open As Source Code. Add capabilities for privacy, motion usage etc.

<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
    <string>Your explanation.</string>
<key>NSLocationAlwaysUsageDescription</key>
    <string>Your explanation.</string>
<key>NSLocationWhenInUseUsageDescription</key>
    <string>Your explanation.</string>
<key>NSMotionUsageDescription</key>
    <string>Your explanation.</string>

Background location

<key>UIBackgroundModes</key>
    <array>
        <string>fetch</string>
        <string>location</string>
        <string>remote-notification</string>
    </array>

📘

Background location request explanation for users and Apple inc.

The most popular explanation is: We're using location services to determine your driving style.

App delegate

Important notifications

Note that these notifications are customized, you can use your own text.
Low power mode

@interface AppDelegate () <RPLowPowerModeDelegate> {
        [RPEntry instance].lowPowerModeDelegate = self;
}

Delegate method:

- (void)lowPowerMode:(Boolean)state {
    if (state) {
        // You can create push in this place and fire about this, as example 
        
        UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc] init];
        content.title = @"Low Power Mode";
        content.body = [NSString stringWithFormat:@"Your trips may be not recorded. Please, follow to Settings=>Battery=>Low Power"];
        UNTimeIntervalNotificationTrigger *trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:1 repeats:NO];
        UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:@"overspeed" content:content trigger:trigger];

        [[UNUserNotificationCenter currentNotificationCenter] addNotificationRequest:request withCompletionHandler:nil]; 
    }
}

Low accuracy

@interface AppDelegate () <RPAccuracyAuthorizationDelegate> {
        [RPEntry instance].accuracyAuthorizationDelegate = self;
}

Delegate method:

- (void)wrongAccuracyAuthorization {
    // You can create push in this place and fire about this, as example 
        
    UNMutableNotificationContent *content = [[UNMutableNotificationContent alloc] init];
    content.title = @"Precise Location is off";
    content.body = [NSString stringWithFormat:@"Your trips may be not recorded. Please, follow to App Settings=>Location=>Precise Location"];
    UNTimeIntervalNotificationTrigger *trigger = [UNTimeIntervalNotificationTrigger triggerWithTimeInterval:1 repeats:NO];
    UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:@"overspeed" content:content trigger:trigger];

    [[UNUserNotificationCenter currentNotificationCenter] addNotificationRequest:request withCompletionHandler:nil];

}

Permissions wizard

Note that the SDK has a built-in Permissions Wizard and a Permissions Dialog that are fully customizable. Wizard for iOS app

Here you can find an example with the correct Permissions Wizard flow:
Permissions in iOS

Setting up the permissions wizard

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [[RPPermissionsWizard returnInstance] launchWithFinish:^(BOOL showWizzard) {
        [RPEntry initializeWithRequestingPermissions:YES]; // Yes, if you don’t want to implement requesting by yourself

        [RPEntry instance].disableTracking = NO;
        [RPEntry application:application didFinishLaunchingWithOptions:launchOptions];
    }];
}
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    RPPermissionsWizard.returnInstance().launch(finish: { _ in
        RPEntry.initialize(withRequestingPermissions: true)
        let token = NSString(string: "Please, enter your Token")
        RPEntry.instance().virtualDeviceToken = token
        let options = launchOptions ?? [:]
        RPEntry.application(application, didFinishLaunchingWithOptions: options)
    })
    return true
}

App delegate methods

- (void)application:(UIApplication *)application handleEventsForBackgroundURLSession:(nonnull NSString *)identifier completionHandler:(nonnull void (^)(void))completionHandler {
    [RPEntry application:application handleEventsForBackgroundURLSession:identifier completionHandler:completionHandler];
}

- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
    [RPEntry applicationDidReceiveMemoryWarning:application];
}

- (void)applicationWillTerminate:(UIApplication *)application {
    [RPEntry applicationWillTerminate:application];
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    [RPEntry applicationDidEnterBackground:application];
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    [RPEntry applicationDidBecomeActive:application];
}

- (void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
    [RPEntry application:application performFetchWithCompletionHandler:^{
        completionHandler(UIBackgroundFetchResultNewData);
    }];
}
func application(_ application: UIApplication, handleEventsForBackgroundURLSession identifier: String, completionHandler: @escaping () -> Void) {
    RPEntry.application(application, handleEventsForBackgroundURLSession: identifier, completionHandler: completionHandler)
}

func applicationDidReceiveMemoryWarning(_ application: UIApplication) {        RPEntry.applicationDidReceiveMemoryWarning(application)
}

func applicationWillTerminate(_ application: UIApplication) {
    RPEntry.applicationWillTerminate(application)
}

func applicationDidEnterBackground(_ application: UIApplication) {
    RPEntry.applicationDidEnterBackground(application)
}

func applicationDidBecomeActive(_ application: UIApplication) {
    RPEntry.applicationDidBecomeActive(application)
}

func application(_ application: UIApplication, performFetchWithCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
    RPEntry.application(application) {
        completionHandler(.newData)
    }
}

Enable high-frequency data collection (Accurate and persistent dataset)

📘

We strongly recommend keeping it enabled by default

[RPEntry enableHF:true];
RPEntry.enableHF(true)

Enable SDK

Set a DeviceToken to SDK to enable it / SDK Log in.

📘

Empty or nil DeviceToken is not allowed

[RPEntry instance].virtualDeviceToken = [self getDeviceToken];

Log out SDK

[[RPEntry instance] removeVirtualDeviceToken];

Usage example for log in/ log out to follow the host app

if ([self userIsAuthenticated]) {
    [RPEntry instance].virtualDeviceToken = [self getDeviceToken];
} else {
    /// empty device token is not allowed
    /// Use removeVirtualDeviceToken method for log out from the host app.
    [[RPEntry instance] removeVirtualDeviceToken];
}

Did this page help you?