Utilize the User Context API
Query for the User's Current Context
Sentiance.shared.requestUserContext { context, error in
guard let context = context else {
print("Error: \(error?.failureReason)")
return
}
print("Recent events:")
// Print the recent events
context.events.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: \(toStringMode(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")
}
print("")
})
// Print the home & work locations, semantic time, and last known location
print("Home venue: \(context.home)")
print("Work venue: \(context.work)")
print("Semantic time: \(toString(context.semanticTime))")
print("Last known location: \(context.lastKnownLocation)")
// Print the user's active segments
print("Active segments:")
context.activeSegments.forEach { segment in
print(" Category: \(toString(segment.category))")
print(" Subcategory: \(toString(segment.subcategory))")
print(" Type: \(toString(segment.type))")
print(" Start date: \(toString(segment.startDate))")
print(" End date: \(toString(segment.endDate))")
print(" Attributes: ")
segment.attributes.forEach { attribute in
print(" \(attribute.name): \(attribute.value)")
}
}
}Subscribe for User Context Updates
Last updated