Get started

Prerequisite

Before starting DriveKit Driver Data integration, make sure that you have initialized DriveKit.

Integration

Get framework

The Driver Data SDK is available on Cocoapods master repo.
To access framework in the repository, add the following lines to your Podfile:
Podfile
1
target 'my-target' do
2
pod 'DriveKitDriverData'
3
end
Copied!
Then, run pod install.

Initialization

An initialization phase is required to use the feature included in the Driver Data SDK. In the application's AppDelegate file, import DriveKitDriverData:
1
import DriveKitDriverDataModule
Copied!
Then, to initialize Driver Data SDK in your app, you must call the initialization method in didFinishLaunchingWithOptions method of your AppDelegate file.
AppDelegate.swift
1
import DriveKitCoreModule
2
import DriveKitTripAnalysisModule
3
4
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
5
DriveKit.shared.initialize()
6
DriveKitDriverData.shared.initialize()
7
...
8
}
Copied!

Check your configuration

You can check if Driver Data SDK is well configured with the following method:
1
DriveKitDriverData.shared.isConfigured
Copied!
This method returns true if it is well configured.

Get driver trips

To get Driver trips, you have to call the following method:
1
public func getTripsOrderByDateDesc(type: SynchronizationType = .defaultSync, completionHandler : @escaping (TripSyncStatus, [Trip]) -> ())
Copied!
SynchronizationType can have 2 values:
  • defaultSync: if this value is used, the SDK will try to synchronize local trips with DriveQuant backend to get new trips or modified trips, and then return the trip list via the completionHandler.
  • cache: if this value is used, no synchronization will be performed and only trips previously synchronized will be returned via the completionHandler.
TripSyncStatus in the completionHandler can have 4 values:
  • noError: Synchronization has been successfully performed.
  • cacheDataOnly: SynchronizationType has been set to cache.
  • failedToSyncTripsCacheOnly: Synchronization has failed, only trips previously synchronized are returned.
  • syncAlreadyInProgress: A synchronization is in progress, only trips previously synchronized are returned until the synchronization is finished.
Trips are returned and sorted by end date in descending order.
If train trips have been recorded by Trip Analysis SDK, they won't be returned by this method.
Example:
1
DriveKitDriverData.shared.getTripsOrderByDateDesc(completionHandler: {status, trips in
2
// Check status and use trips data
3
})
Copied!

Get specific trip

To get a specific trip, you have to call the following method:
1
public func getTrip(itinId : String, completionHandler: @escaping (TripSyncStatus, Trip?) -> ())
Copied!
The itinId parameter is the unique identifier for a trip.
When you call this method, you will get trip data and trip safety events. If safety events are not synchronized locally for the trip, a synchronization with DriveQuant backend will be performed and then, the trip will be returned with safety events synchronized.
TripSyncStatus can have the same value as above and the value failedToSyncSafetyEvents if the safety events synchronization failed.
Example:
1
DriveKitDriverData.shared.getTrip(itinId: itinId, completionHandler: {status, trip in
2
// Check status and use trip data
3
})
Copied!

Get trip road data

To get road data of the trip (latitude, longitude), you have to call the following method:
1
public func getRoute(itinId: String, completionHandler : @escaping (Route?) -> ())
Copied!
If route value in completionHandler is nil , the synchronization has failed.
Example:
1
DriveKitDriverData.shared.getRoute(itinId: itinId, completionHandler: { route in
2
if let route = route {
3
// Use route data
4
}else{
5
// Failed to synchronize route
6
}
7
})
Copied!

Delete a trip

To delete a trip, you have to call the following method:
1
public func deleteTrip(itinId: String, completionHandler : @escaping (Bool) -> ())
Copied!
The itinId parameter is the unique identifier for a trip.
Example:
1
DriveKitDriverData.shared.deleteTrip(itinId: self.viewModel.itinId, completionHandler: {deleteSuccessful in
2
if deleteSuccessful {
3
// trip successfully deleted
4
} else {
5
// Failed to delete trip
6
}
7
})
Copied!

Get driver synthesis

To get driver synthesis data, you have to call the following method:
1
public func getSynthesis(type: SynchronizationType = .cache, completionHandler: @escaping (SynthesisSyncStatus, DKSynthesis?) -> ())
Copied!
SynchronizationType can have 2 values:
  • defaultSync: if this value is used, the SDK will try to synchronize the driver synthesis data with DriveQuant backend and then return it via the completionHandler.
  • cache: if this value is used, no synchronization will be performed and the data retrieved during the last synchronisation will be returned via the completionHandler.
SynthesisSyncStatus in the completionHandler can take 3 values:
  • cacheDataOnly: SynchronizationType has been set to cache.
  • noError: Synchronization has been successfully performed.
  • failedToSyncSynthesisCacheOnly: Synchronization has failed, only data retrieved during the last synchronisation is returned.
Example:
1
import DriveKitDriverDataModule
2
3
DriveKitDriverData.shared.getSynthesis(type: .defaultSync) { status, synthesis in
4
// Check status and use synthesis
5
}
Copied!

Get driver timelines

To get driver timelines, you have to call the following method:
1
public func getTimelines(periods: [DKTimelinePeriod], type: SynchronizationType = .cache, completionHandler: @escaping (TimelineSyncStatus, [DKTimeline]?) -> ())
Copied!
periods attribute contains periods you are interested in: .week and/or .month.
SynchronizationType can have 2 values:
  • defaultSync: if this value is used, the SDK will try to synchronize timelines with DriveQuant backend and then return them via the completionHandler.
  • cache: if this value is used, no synchronization will be performed and the data retrieved during the last synchronisation will be returned via the completionHandler.
TimelineSyncStatus in the completionHandler can take 4 values:
  • cacheDataOnly: SynchronizationType has been set to cache.
  • noError: Synchronization has been successfully performed.
  • failedToSyncTimelineCacheOnly: Synchronization has failed, only data retrieved during the last synchronisation are returned.
  • noTimelineYet: Synchronization has been successfully performed and there is currently no timeline.
Example:
1
import DriveKitDriverDataModule
2
3
DriveKitDriverData.shared.getTimelines(periods: [.week, .month], type: .defaultSync) { (status, timelines) in
4
// Check status and use timelines
5
}
Copied!

Reset

If you need to reset Driver Data configuration (user logout for example), you can call the following method:
1
DriveKitDriverData.shared.reset()
Copied!
All data saved locally by DriverData SDK will be erased and default configuration will be restored.
Last modified 1yr ago