CLLocationManager.location为nil

这是我的locationManager init方法:

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

在调用此方法之后这一行

 println(self.locationManager.location) 

打印为零,为什么会这样? 它在过去对我很有用我只是在我的应用程序中做了一些更改,它现在不能正常工作..

1) CLLocation位置文档 – 如果从未检索过位置数据,则此属性的值为nil。

2)您已为CLLocationManager设置委托。 为什么不实现locationManager:didUpdateLocations:并从内部打印最新检索的位置?

3)您使用的是模拟器还是真实的设备? 请记住,如果您使用的是模拟器,则可能需要启用模拟位置:

Xcode位置落下

您还可以在以下Custom Location找到Custom Location选项: – Simulator -> Debug -> Location -> Custom Location...

从iOS 8开始,如果您没有在Info.plist中为NSLocationAlwaysUsageDescription提供字符串, NSLocationAlwaysUsageDescription忽略requestAlwaysAuthorization

链接到文档