Utilize the Event Timeline API
On this page, you can find examples of how to query the Sentiance SDK for historic timeline events, and how to register to receive timeline updates in your app, as new events are detected or existing ones are updated.
Query for Historic Events
let from = Date.distantPast
let to = Date.distantFuture
Sentiance.shared.getTimelineEvents(from: from, to: to).forEach { event in
print("Event ID: \(event.eventId)")
print("Started on: \(event.startDate)")
print("Ended on: \(event.endDate)")
if event.type == .inTransport {
let transport = event as! SENTTransportEvent
print("Type: transport")
print("Mode: \(transport.transportMode)")
if let distance = transport.distanceInMeters {
print("Distance: \(distance)")
}
print("Waypoints: \(transport.waypoints)")
}
else if event.type == .stationary {
let stationary = event as! SENTStationaryEvent
print("Type: stationary")
print("Location: \(stationary.location)")
print("Venue: \(stationary.venue)")
}
else if event.type == .offTheGrid {
print("Type: off-the-grid")
}
else {
print("Type: unknown")
}
}Subscribe for Event Timeline Updates
To get event timeline 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 event timeline SDK or other 3rd party plugin APIs inside your registerEventTimelineListener Dart function, then you need to register these plugins with the Sentiance SDK. See this for more details.
Last updated