Utilize the Driving Insights API
On this page, you can find examples of how to query the Sentiance SDK for driving insights, and how to register to receive real time driving insights in your app, for completed transports.
Query for Driving Insights
if let drivingInsights = Sentiance.shared.getDrivingInsights(forTransportId: transportId) {
let event = drivingInsights.transportEvent
let safetyScores = drivingInsights.safetyScores
print("Focus score: \(safetyScores.focusScore ?? -1)")
print("Legal score: \(safetyScores.legalScore ?? -1)")
print("Smooth score: \(safetyScores.smoothScore ?? -1)")
print("Call-while-moving score: \(safetyScores.callWhileMovingScore ?? -1)")
print("Overall score: \(safetyScores.overallScore ?? -1)")
print("Event ID: \(event.eventId)")
print("Started on: \(event.startDate)")
print("Ended on: \(String(describing: event.endDate))")
print("Mode: \(event.transportMode)")
if let distanceInMeters = event.distanceInMeters {
print("Distance: \(distanceInMeters)")
}
print("Waypoints: \(event.waypoints)")
}Subscribe for Driving Insights Updates
To get driving insights updates even when your app is in the background, place the following code inside your app's entrypoint index.js file. If you're only interested in these updates when your app is foregrounded, place this code inside the appropriate UI code instead.
Create a background.dart file under your project's lib folder with the following code:
Add the following code, depending on your target platform.
For iOS, add the following to your app delegate class:
For Android, add this code to your custom application class:
If you're calling other APIs from the driving insights SDK or other 3rd party plugin APIs inside your registerDrivingInsightsListener Dart function, then you need to register these plugins with the Sentiance SDK. See this for more details.
Query For Driving Events
Last updated