Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lazily asking for Location Services

As soon as I install and launch my app for the first time, it immediately asks for location services, even though startUpdatingLocation hasn't been called. I haven't even allocated a CLLocationManager instance at that point. I'd like this prompt to be done lazily after I actually make the call so the user doesn't blindly turn it off. Has this flow changed with iOS recently? I remember it used to be lazily asked. I'm using 5.1 firmware.

like image 421
Shaun Budhram Avatar asked Apr 13 '12 06:04

Shaun Budhram


1 Answers

Thats interesting. I tested your hypothesis, that the location manager isn't even allocated and yet the iOS Location Permission dialogue comes up. I tried the following troubleshooting. After every step I ran the project on a device and I could only get the location popup to appear at the last step.

  • Start a new app
  • require location-services in info.plist
  • require gps in info.plist
  • link CoreLocation to the project
  • Import Core Location into header
  • Make and synthesise a property for a location manager
  • ask CLLocationManager for +authorizationStatus
  • ask CLLocationManager for +locationServicesEnabled
  • alloc init a CLLocationManager instance
  • tell CLLocationManager to start updating location.

Only the final step brought up a prompt. To be sure i even created a viewController that pushed a second view controller that initialised a CLLocationManager and started updating the location. The permission popup only came up when the second view controller was pushed. This is all with the latest Xcode running on 5.1.

I have shown that location services still only asks for permission at the exact moment you try and turn locations on like it has done in previous SDKs. Perhaps check your code, maybe paste some here so we can go into more detail. :)

like image 84
jackslash Avatar answered Oct 13 '22 17:10

jackslash