25

I just can get my CLLocationManager to authorise. (swift under ios8) I even add an explicit requestAlwaysAuthorization call (which I don't need with objC under ios7)

func finishLaunch() {
    //ask for authorization
    let status = CLLocationManager.authorizationStatus()
    if(status == CLAuthorizationStatus.NotDetermined) {
        self.locationManager.requestAlwaysAuthorization();
    }
    else {
        self.startMonitoring()
    }
    ...
}

the callback never gets anything but NotDermined and there is no UIAlertView shown to the user.

func locationManager(manager: CLLocationManager!, didChangeAuthorizationStatus status: CLAuthorizationStatus) {
    if(status == CLAuthorizationStatus.NotDetermined) {
        println("Auth status unkown still!");
    }
    self.startMonitoring()
}

Am I doing it wrong? -- Feels like a bug to me but I'd like some feedback

Jojodmo
  • 23,357
  • 13
  • 65
  • 107
Daij-Djan
  • 49,552
  • 17
  • 113
  • 135

3 Answers3

41

Keep in mind that NSLocationAlwaysUsageDescription or NSLocationWhenInUseUsageDescription keys are now mandatory, so you should include that in your plist.

Klaas
  • 22,394
  • 11
  • 96
  • 107
amb
  • 4,798
  • 6
  • 41
  • 68
  • 2
    thanks for your support. The bug is still valid because I couldn't even authorise it via the settings app but this was the solution for me – Daij-Djan Jun 04 '14 at 13:19
  • For anyone still confused as to whether they have entered these keys correctly: http://stackoverflow.com/questions/24082188/localizing-the-user-on-ios-8 shows it precisely – sam_smith Oct 01 '14 at 05:19
  • 1
    and put them in the right `plist`! (I first edited the `test-plist` instead of the `application-plist`) – longi Nov 03 '14 at 09:22
3

The only thing that you have to do is to add the Key "NSLocationWhenInUseUsageDescription" to your app info.plist then make a CLLocationManager requestWhenInUseAuthorization method and call it in the viewDidLoad.

  • Actually I run it in the delegate didFinishLoading as I have no CLLocationManager in the map controller, but it gets ignored even after entering the entry in the info.plist always returning: "Trying to start MapKit location updates without prompting for location authorization. Must call -[CLLocationManager requestWhenInUseAuthorization] or -[CLLocationManager requestAlwaysAuthorization] first". – Fabrizio Bartolomucci Jun 06 '14 at 12:50
  • @FabrizioBartolomucci, when you call requestWhenInUseAuthorization/requestAlwaysAuthorization, is the CLLocationManager object one that was allocated locally? If so, it'll be released when you exit didFinishLoading, and when the user taps "Allow" there will be no location manager to save the results. You need a global/strong referenced location manager (I made it a property of my Application delegate). – Timo Bruck Jun 06 '14 at 23:26
  • @Tiago thanks but smb already helped me - I was missing the code – Daij-Djan Jun 08 '14 at 14:48
  • Funny: that code worked fine for years before iOS 8. In fact I remember running the manager worked quite like creating an NSUrlConnection, what automatically happens by retaining it. Perhaps that has changed in iOS 8. Good to know, thanks, I will give it a test soon. – Fabrizio Bartolomucci Jun 09 '14 at 16:27
  • I checked it. My CLLocationManager variable is safe outside the method. – Fabrizio Bartolomucci Jun 09 '14 at 20:07
  • 1
    And it keeps on not working. The Apple team tells it may not answer questions regarding pre-release software but he confirmed there are issue about localizations in iOS 8. Do you know here it is possible to submit pre-release bugs? – Fabrizio Bartolomucci Jun 10 '14 at 14:29
  • Might help some with the plist editor to right click and select show Raw... This lets you see the actual key names better. – dfowler7437 Jun 24 '15 at 23:52
1

As it happens with my objC app as well -- the one I KNOW works fine under ios7 -- I figured it should be a OS bug and reported it: #17128352

Daij-Djan
  • 49,552
  • 17
  • 113
  • 135
  • Do you get any updates on ``didUpdateToLocations`` in iOS 8?? I'm not receiving any locations in the delegate. – amb Jun 04 '14 at 08:49
  • 1
    if I go to settings>privacy>location services and authorise the app WHILE it is running - then I do! until I restart the app – Daij-Djan Jun 04 '14 at 08:56
  • correction: it turns authorisation off randomly - even if I don't restart :D – Daij-Djan Jun 04 '14 at 09:43
  • 1
    Well, this did the trick: ``if ([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) { [self.locationManager requestAlwaysAuthorization]; }`` – amb Jun 04 '14 at 09:51
  • 1
    Keep in mind that ``NSLocationAlwaysUsageDescription`` key is now mandatory, so you should include that in your plist. EDIT: is mandatory depending on your location authorisation method. For in-use auth, use ``NSLocationWhenInUsageDescription`` – amb Jun 04 '14 at 10:02
  • 1
    @amb: ha that was it! please post that as an answer – Daij-Djan Jun 04 '14 at 11:48
  • @Daij-Djan I have authorise the app in settings>privacy>location services. But I still can get anything in `func locationManager(manager: CLLocationManager!, didUpdateLocations locations: AnyObject[]!)` Do you have any idea why? Thanks – Jake Lin Jun 04 '14 at 12:33
  • NSLocationWhenInUsageDescription didn't work for me. it showed the alert, but no mattered if i clicked on 'allow' or 'deny', nothing changed, and the didChangeAuthorizationStatus delegate was not called. (requestAlwaysAuthorization did work). maybe it's a bug indeed. – tomeron11 Jul 20 '14 at 14:35