here-ios-sdk-examples icon indicating copy to clipboard operation
here-ios-sdk-examples copied to clipboard

GuidanceSpeedMonitor in the Background

Open OllieJohnson-dev opened this issue 5 years ago • 1 comments

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

OllieJohnson-dev avatar Jan 31 '20 10:01 OllieJohnson-dev

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.

HERE-SDK-Support-Team avatar Feb 04 '20 12:02 HERE-SDK-Support-Team