Reputation: 575
I'm using XCode 7.0 Beta and Swift.
I'm using MKMapView to display some places on a Map. Everything is ok : I see the Map and the place on the Map but I've the following error message :
Trying to start MapKit location updates without prompting for location authorization. Must call -[CLLocationManager requestWhenInUseAuthorization] or -[CLLocationManager requestAlwaysAuthorization] first.
In the Info.plist file, I've added NSLocationAlwaysUsageDescription and NSLocationWhenInUseUsageDescription (see screenshot)
> <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC
> "-//Apple//DTD PLIST 1.0//EN"
> "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist
> version="1.0"> <dict> <key>NSLocationAlwaysUsageDescription</key>
> <string>Test is NSLocationAlwaysUsageDescription</string>
> <key>NSLocationWhenInUseUsageDescription</key> <string>This is
> NSLocationWhenInUseUsageDescription</string>
In viewDidLoad, I've the following code
import UIKit
import MapKit
import CoreLocation
class ViewController: UIViewController {
@IBOutlet weak var btn: UIButton!
@IBOutlet weak var Map: MKMapView!
@IBAction func btnClick(sender: AnyObject) {
}
override func viewDidLoad() {
super.viewDidLoad()
let locationManager = CLLocationManager()
var CLAuthStatus = CLLocationManager.authorizationStatus()
if(CLAuthStatus == CLAuthorizationStatus.NotDetermined) {
locationManager.requestAlwaysAuthorization();
}
When I run the code, in the simulator, I don't have any warning or any prompt to ask me the authorisation.
What's wrong ?
Thanks in advance
Have a nice day
Ghislain
Upvotes: 2
Views: 1605
Reputation: 683
I had faced with the same problem before. Did you add Privacy - Location Usage Description to the info.plist ?
Upvotes: 0
Reputation: 14884
I think I had the same or similar problem. I had all the code right but the user never was asked for authorization and the authorization status was always .Undetermined. I suspect the user request was presented but was behind the mapView so it couldn't be seen. If your problem is the same as mine you can fix it like this: On the device go to Settings / Privacy / Location Services. Tap on Location Services then scroll down to the name of your app and tap on it and see a group named "ALLOW LOCATION SERVICES" with Never and Always. Below that you'll see the String you put in the .plist file. Select "Always" (if that's what you want) and try running again and see if that fixes it.
Upvotes: 0