Access to the On Device Sentiance Insights is available through the APIs exposed by the Sentiance SDK (iOS, Android, React Native and Flutter) .
Available Insights
The On Device API provides access to following insights:
Driving Insights
Mobility Insights
Lifestyle Insights
Fetching Insights
Depending on your use-case and the technical design of your application, you have two options to retrieve insights:
Querying the SDK on Demand
Listening to Callbacks for Real-time Updates
Querying the SDK on Demand
You can query the SDK for insights at any point in your application codebase. The following example demonstrates how to fetch the recent trips:
let currentDate =Date()let calendar = Calendar.currentlet fiveDaysAgo = calendar.date(byAdding: .day, value:-5, to: currentDate)let events = Sentiance.shared.getTimelineEvents(from: fiveDaysAgo!, to: currentDate)events.forEach { event inprint(event.eventId)}
val from =Date(0)val to =Date(Long.MAX_VALUE)EventTimelineApi.getInstance(context).getTimelineEvents(from, to).forEach { event ->print("Event ID: ${event.id}")}
Coming soon: Example code for listening for transport updates
Synchronising Insights with Your Backend
A common practice when utilizing On-Device Insights involves ensuring the insights are effectively synchronised with your backend storage systems. This step is essential for integrating real-time data insights directly into your data management workflows.
Deciding on the optimal placement of listeners is crucial for syncing data with your backend, based on whether the application is in the foreground or background. This ensures that the insights remain accessible to the underlying systems at all times.
For background syncing, place listeners in startup scripts to activate when the app is woken by the OS. For foreground syncing, integrate listeners either in startup scripts or in specific startup functions as the user begins their session, ensuring seamless data sync with your backend in all app states.
Insert the listeners within AppDelegate.swift file just following the Sentiance.shared.initialize initiation step. This placement ensures they are primed to manage background processes as soon as the application initiates.
Insert the listeners within MainApplication.kt class just following the Sentiance.getInstance(this).initialise() initiation step. This placement ensures they are primed to manage background processes as soon as the application initiates.
The Sentiance SDK automatically activates the index.js file when the app is woken up, eliminating the need for background syncing setup in the native code. You can simply add your listeners to the index.js file to handle background activities efficiently.