iOS

This section describes how to integrate DriveKit into an iOS mobile application.

Requirements

DriveKit is developed with the Swift 5 language and is compatible with iOS 10.0 and later versions.

Integration

DriveKit SDK is available on Cocoapods master repo.

To access the framework in the repository, add the following lines to your Podfile:

Podfile
Podfile
target 'my-target' do
pod 'DriveKitCore'
end

Initialization

DriveKit initialization

To initialize DriveKit in your app, you must call the initialization method in didFinishLaunchingWithOptions method of your application class.

AppDelegate.swift
AppDelegate.swift
import DriveKitCoreModule
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
DriveKit.shared.initialize()
...
}

All DriveKit modules have a method initialize that must be called in didFinishLaunchingWithOptions method of your AppDelegate file.

Add API key

To use DriveKit framework, you have to obtain an API Key from DriveQuant. If you don't have an API key, please contact DriveQuant.

Once your API key is securely stored in your application, you can configure DriveKit by calling the following method:

Untitled
DriveKit.shared.setApiKey(key: "MyApiKey")

Identify user

Each driver must be identified with a unique identifier. Once you have this identifier, configure DriveKit by calling the following method:

Untitled
DriveKit.shared.registerUser(userId: "MyUserId")

You can call these 2 configuration methods anywhere in your app code. DriveKit will save the value locally. If the app is killed and relaunched, DriveKit will be reconfigured automatically.

DriveKit SDK will not work until you set the API key and the userId.

Check your configuration

You can check if DriveKit SDK is well configured with the following method:

Untitled
DriveKit.shared.isConfigured()

This method returns true if it is well configured.

Reset

If you need to reset DriveKit configuration (user logout for example), you can call the following method:

Untitled
DriveKit.shared.reset()

All data saved locally by DriveKit will be erased.

All DriverKit frameworks have reset method that erases all data saved locally by the framework.

Make sure that you call reset method of all frameworks to fully reset DriveKit configuration.

Logging

To facilitate integration, DriveKit provides a logging feature. To activate logging, call the following method:

Untitled
DriveKit.shared.enableLogging()

Log will be written in app directory. One log file per month will be written with the name log-<MONTH>-<YEAR>.txt (example: log-8-2019.txt). All DriveKit modules log in this file.

To write log files on user smartphone, you must add the following entry in your info.plist file UIFileSharingEnabled and LSSupportsOpeningDocumentsInPlace set to true .

Disable logging by calling:

Untitled
DriveKit.shared.disableLogging()

xCode 12 Updates

After the deployment of iOS 14 and the new development tool Xcode 12, the distribution format of the DriveKit SDK has changed. We now use the XCFramework distribution format recommended by Apple.

This change requires some modifications to integrate version 1.6.3 of the DriveKit SDK and later versions.

  • The module names had to be modified to not match the name of a class present in the module. Pod names have not been modified.

  • Pods must be installed with Cocoapods version 1.10.0 because this version fixes a bug in the support of the XCFramework format needed for the DriveKit SDK to work properly. A release candidate is available and can be installed with the following command: sudo gem install cocoapods --pre

Changing module names requires the update of all DriveKit imports in the source code of your application. To simplify this operation, we invite you to use the migration script available here.

Just retrieve this script, drop it at the root of your Xcode project, where your Podfile is located, and run it. Thus, DriveKit imports of your different source files (Swift, ObjC) will be updated automatically.

Once these modifications have been made, the DriveKit SDK will be fully operational.