CLLocationManager.location is nil

好久不见. 提交于 2019-12-04 20:27:48

问题


this is my locationManager init method:

func initLocationManager() {
        seenError = false
        locationFixAchieved = false
        locationManager = CLLocationManager()
        locationManager.delegate = self
        locationManager.desiredAccuracy = kCLLocationAccuracyBest
        locationManager.requestAlwaysAuthorization()
        locationManager.startUpdatingLocation()     
}

after calling this method this line

println(self.locationManager.location)

prints nil why is that? it worked for me well at the past i just made few changes in my app and it doesn't work well now..


回答1:


1) CLLocation location documentation - The value of this property is nil if no location data has ever been retrieved.

2) You've set the delegate for CLLocationManager. Why not implement locationManager:didUpdateLocations: and print the latest retrieved location from inside?

3) Are you using a simulator or a real device? Bear in mind that if you are using a simulator you may need to enable simulate location:

You can also find a Custom Location option in: - Simulator -> Debug -> Location -> Custom Location...




回答2:


As of iOS 8 requestAlwaysAuthorization is ignored if you do not provide a string for NSLocationAlwaysUsageDescription in your Info.plist.

Link to documentation



来源:https://stackoverflow.com/questions/27093422/cllocationmanager-location-is-nil

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!