Code below should get current location. But above error is generated. Function didUpdateLocations never gets called.
Running this on a device (iPhone 5s)iOS 9.1. Info.plist has Required device capabilities and Privacy - Location usage description configured as shown in the attached image. Please help!
let locationManager = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
locationManager.delegate = self
locationManager.requestAlwaysAuthorization()
locationManager.requestLocation()
}
func locationManager(manager: CLLocationManager,
didFailWithError error: NSError)
print(error.description)
}
func locationManager(manager: CLLocationManager, didUpdateLocations
locations: [CLLocation]) {
print(“got location”)
}
searching google true the answers this seems to be a problem since IOS4.0.
in XCODE 7.1 under Project => scheme => edit scheme.
under Run => Options => Core location / disable Allow Location Simulation.
in your IOS Simulator under Debug => Location select a location. This fixed the problem for me.
If the location authorization alert is not popping up for you, try adding NSLocationAlwaysUsageDescription to your plist as type string. Also, do the same for NSLocationWhenInUseUsageDescription.
I was having the same issue with an app that I was moving from 8.0 -> 9.0/9.1. I tried a couple of things like write the CLLocationManager portion only in Swift and a new Obj-C project as well. I also tested it on different devices. To solve the issue on the device, I removed the didFailWithError func. Which stops the error altogether. This may not seem the best idea but in IOS9 you can limit your application to devices that have GPS or Location-Services. Android has been doing this for a really long time. I also noticed in your .plist your don't have the permissions enabled for NSLocationALwaysUsageDescription or the NSLocationWhenInUseUsageDescrtiption properties included.
Just for reference I have attached what my current .plist looks like that does not fire this error as well as a code chunk in obj-c the controller file. The code starts at the very end of a previous function and then has the commented out didFailWithError delegate and the didUpdateLocations. Currently this is working successfully in IOS 9.1
Please try this :
Go to :
EDIT : As mentionned in the comments, also restart Xcode and you're done !
Hope this helps.
Try this from the Simulator --> Debug --> Location
I have these suggestions for people using apple maps in their app