0

I've tried looking at other solutions such as: requestWhenInUseAuthorization() not Work in iOS 8 With NSLocationWhenInUseUsageDescription Key in Info.plist

But I can't get authorization prompt to get location.

That person's issue in that other question was that he had is manager inside his viewDidLoad, I do not, but still an authorization prompt is not showing up. I've updated my plist:

gyazo.com/b66946b9976aa226a21c0bf6e3817e3a

and have my manager outside of my viewDidLoad:

import UIKit
import AVFoundation
import MapKit

class SecondViewController: UIViewController, CLLocationManagerDelegate {

let locationManager: CLLocationManager = CLLocationManager()


var player = AVPlayer()
override func viewDidLoad() {
    super.viewDidLoad()
    self.locationManager.delegate = self
    self.locationManager.desiredAccuracy = kCLLocationAccuracyBest
    self.locationManager.requestWhenInUseAuthorization()
    self.locationManager.startUpdatingLocation()
    println("Got to end of locationmanager")
    //playentryaudio() // User plugged in mic -- start playing entry audio.
}

func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) {
    println("Got to locationmngsr")
    var userlocation = locations[0] as! CLLocation

    var latitude: CLLocationDegrees = userlocation.coordinate.latitude

    var longitude: CLLocationDegrees = userlocation.coordinate.longitude

    println(latitude)
    println(longitude)
} //snip rest of code

Since It's not getting auth, It's never hitting the locationManager function.

Community
  • 1
  • 1
Ajax jQuery
  • 357
  • 1
  • 5
  • 19

1 Answers1

1

The prompt only shows if CLLocationManager.authorizationStatus() == .NotDetermined. If the user previously denied access, you won't see the prompt anymore. You should check the status before self.locationManager.requestWhenInUseAuthorization(). If it shows anything but .NotDetermined, look at the location settings for the app and the device.

If the status is .NotDetermined and the prompt still does not show, I would double check spelling of the NSLocationWhenInUseUsageDescription.

MirekE
  • 11,515
  • 5
  • 35
  • 28
  • I'll check, but I'm running this in the emulator and never even got the request, unless the emulator sets the status to denied by default. – Ajax jQuery Aug 23 '15 at 17:58
  • The emulator does not set the status to denied by default, but I think it would be a good idea to check the actual status programmatically to rule out one possibility. – MirekE Aug 23 '15 at 18:04
  • That if statement returned true (Not Determined). I tried printing `CLLocationManager.authorizationStatus()` to see the actual status, but it prints saying that It's a 'enum value'. – Ajax jQuery Aug 23 '15 at 18:16
  • In that case everything shown looks just fine. One thing I do not see though is the full name of the `NSLocationWhenInUseUsageDescription` string. Are you sure the spelling is correct and there are no extra spaces at the end? – MirekE Aug 23 '15 at 18:41
  • Yep -- It's an exact match. – Ajax jQuery Aug 23 '15 at 19:32