iOS SDK

Easily integrate the Telematics SDK into your iOS project using Swift Package Manager or CocoaPods. Follow this step-by-step guide to import, initialize, and configure the SDK for accurate trip tracking, low-power mode notifications, accident detection, and high-frequency data collection. Get started today!

Adding the SDK to your project

Swift Package Manager

in Package.swift add the following:

dependencies: [
  .package(url: "https://github.com/Mobile-Telematics/telematicsSDK-iOS-new-SPM", from: "<latest version. example:7.0.0>")
],
targets: [
  .target(
    name: "MyProject",
    dependencies: [..., "TelematicsSDK"]
  )
  ...
]

Install CocoaPods

pod 'TelematicsSDK'

SDK import

import TelematicsSDK
import <TelematicsSDK/TelematicsSDK.h>

SDK Initialization

RPEntry.initializeSDK()
[RPEntry initializeSDK];

App delegate

func application(_ application: UIApplication, handleEventsForBackgroundURLSession identifier: String, completionHandler: @escaping () -> Void) {
    RPEntry.instance.application(application, handleEventsForBackgroundURLSession: identifier, completionHandler: completionHandler)
}

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

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

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

func applicationWillEnterForeground(_ application: UIApplication) {
    RPEntry.instance.applicationWillEnterForeground(application)
}

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

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

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

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

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

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

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

- (void)application:(UIApplication *)application performFetchWithCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
    [[RPEntry instance] application:application performFetchWithCompletionHandler:^{
        completionHandler(UIBackgroundFetchResultNewData);
    }];
}

Important notifications

Low power mode

class AppDelegate: RPLowPowerModeDelegate {
    RPEntry.instance.lowPowerModeDelegate = self
}

func lowPowerMode(_ state: Bool) {
        if (state) {
            self.showNotification(title: "Low Power Mode", body: "Your trips may be not recorded. Please, follow to Settings=>Battery=>Low Power")
        }
}

func showNotification(title: String, body: String) {
	let content = UNMutableNotificationContent()
        content.title = title
        content.subtitle = body
        content.sound = UNNotificationSound.default

        let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 5, repeats: false)
        let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: trigger)
        UNUserNotificationCenter.current().add(request)
}
@interface AppDelegate () <RPLowPowerModeDelegate> {
    [RPEntry instance].lowPowerModeDelegate = self;
}

- (void)lowPowerMode:(BOOL)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]; 
    }
}

Permissions wizard

Note that the SDK has a built-in Permissions Wizard and a Permissions Dialog that are fully customizable. To request user's permissions built-in Permissions Wizard can be used or you can implement your own logic to request Always Location permissions and Motion permissions

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
	RPEntry.initializeSDK()
	let options = launchOptions ?? [:]
    RPEntry.instance.application(application, didFinishLaunchingWithOptions: options)
    RPPermissionsWizard.returnInstance().launch(finish: { _ in
    	RPEntry.instance.virtualDeviceToken = "Please, enter your Token"
    	RPEntry.instance.disableTracking = false
    })
    return true
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
	[RPEntry initializeSDK];
	[[RPEntry instance] application:application didFinishLaunchingWithOptions:launchOptions];
    [[RPPermissionsWizard returnInstance] launchWithFinish:^(BOOL showWizzard) {
    	[RPEntry instance].virtualDeviceToken = @"Please, enter your Token"
        [RPEntry instance].disableTracking = NO;
    }];
}

Enable high-frequency data collection (HF)

HF data is enabled by default.

Enable Accident detection.

Accident detection is disabled by default. You can enable detection.

RPEntry.instance.enableAccidents(true)
[[RPEntry instance] enableAccidents:true];

Enable SDK.

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

RPEntry.instance.virtualDeviceToken = "VIRTUAL_DEVICE_TOKEN"
[RPEntry instance].virtualDeviceToken = @"VIRTUAL_DEVICE_TOKEN";

Log out SDK

RPEntry.instance.setEnableSdk(false)
RPEntry.instance.removeVirtualDeviceToken()
[[RPEntry instance] setEnableSdk:NO];
[[RPEntry instance] removeVirtualDeviceToken];

Update SDK to a specific version.

pod 'TelematicsSDK', '7.0.0'

Did this page help you?