here-ios-sdk-examples
here-ios-sdk-examples copied to clipboard
GuidanceSpeedMonitor in the Background
Hi there,
Im trying to capture the speed Limit of the current road segment a user is travelling along. I wish to do this in the background of the Application.
How can this be achieved.
Im using the following sample code but it will only get speedLimits when the app is in the foreground
extension LMLocationManager: GuidanceSpeedMonitorDelegate {
public func guidanceSpeedMonitor(_ monitor: GuidanceSpeedMonitor,
didUpdateCurrentSpeed currentSpeed: Measurement<UnitSpeed>?,
isSpeeding: Bool,
speedLimit: Measurement<UnitSpeed>?) {
let mpsLimit = speedLimit?.converted(to: .metersPerSecond)
self.currentSpeedLimit = mpsLimit.map { NSNumber(value: $0.value) }
let mpsSpeed = currentSpeed?.converted(to: .metersPerSecond)
self.currentSpeed = mpsSpeed.map { NSNumber(value: $0.value) }
Log.info("SpeedLimit: ", speedLimit)
if isSpeeding {
AppModule.auth.user?.journey?.addSpeeding()
}
}
}
Thanks Oliver
Hi Oliver,
Apple has very strict policies for apps running in background. Have you already tried to add a UIBackgroundModes key to your app’s Info.plist file? "fetch" or "remote-notification" sounds suitable.
Note that the guidance example app is designed having a UI case in mind, so background tasks are not explicitly supported by default.
Hope this helps.