mapzen / ios

Where you can find everything iOS from Mapzen
https://mapzen.com/projects/mobile/
Apache License 2.0
40 stars 24 forks source link

Location update when App in background #390

Closed nolispe280 closed 6 years ago

nolispe280 commented 6 years ago

Hi guys, I am trying to make my app update my current location at all times but unfortunately it does not work: after locking my screen or after having my app in the background, the little arrow on the top right corner disappears. I have added the "Privacy - Location Always Usage" and the "Privacy - Location when in Use" in the info.plist but it does not change anything. I also set the app on my phone to "Always" in the Privacy/Location Services Settings. Is there something else that I missed?

msmollin commented 6 years ago

Hello! Saw your note (and responded) on the other issue but I wanted to answer this fully for you just so you can move forward. Take a look at this code here: https://github.com/mapzen/ios/pull/385/files#diff-370c07e6870c5de2f98084242ee19af5R99

You can see what the necessary modification are to get things working. The most important part of that block of code is setting the allowsBackgroundLocationUpdates property on CLLocationManager to true.

However, there is a bug we're fixing as part of that work wherein we'll continue to attempt to make calls to the GPU while in the background, which makes iOS rather upset :) You can see that issue documented here: https://github.com/mapzen/ios/issues/378

I don't think that will cause issues if you instantiate your own CLLocationManager but we haven't tested that instance with the old code mostly because its easier just to focus on supporting background location updates ourselves.

nolispe280 commented 6 years ago

Hello,

Thank you for the comment. Unfortunately, changing the source code according to your link does not change anything. The arrow still disappears after 10 seconds of the App being put in the background or the phone locked. Are you planning on releasing an updated SDK that would include a fully corrected version? And if so, do you know when?

Kind regards,

msmollin commented 6 years ago

@nolispe280 thanks for checking into it. The fix / support is now generally available in master. We hit a snag releasing the SDK in testing due to some backwards compatibility regression testing with iOS 9 support. If you don't support iOS 9, feel free to point your cocoapod at master and we'll work on getting fixes in place in the mean time.

msmollin commented 6 years ago

Snag fixed, and SDK released. https://github.com/mapzen/ios/releases/tag/v1.1.1 and also available in Cocoapods.

nolispe280 commented 6 years ago

Great! I will test it right away

nolispe280 commented 6 years ago

I get an error: Assertion failure in -[CLLocation Manager setAllowsBackgroundLocationUpdates:] ... Terminating app due to uncaught exception 'NSInternalInconsistencyException'
Might be due to the fact that I had to copy and paste the SDK folder (couldn't load it via cocoapods)

nolispe280 commented 6 years ago

I have managed to load the SDK 1.1.1 via cocoapods (had to uninstall and reinstall it). I then added this code in the viewDidLoad function:

if self.locationManager.canEnableBackgroundLocationUpdates() {
        _ = self.locationManager.enableBackgroundLocationUpdates(forType: .other, desiredAccuracy: kCLLocationAccuracyBest, pausesLocationAutomatically: false)
      }

but still get the above error. Does anyone else have this issue?

msmollin commented 6 years ago

Lets move this discussion over to the new issue I just made so we don't muddy feature requests and bugs together.