【发布时间】:2014-06-05 02:25:20
【问题描述】:
我一直试图让它工作一段时间,我来这里是想问 - 我如何在 Swift 中使用 CLLocationManagerDelegate 方法?我把它放在班级的首位:
var locationManager = CLLocationManager()
我已将以下内容放入我的 viewDidLoad 方法中:
locationManager.delegate = self
locationManager.distanceFilter = kCLDistanceFilterNone
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.startUpdatingLocation()
我已经尝试使用这些委托方法但无济于事:
func locationManager(manager: CLLocationManager!, didUpdateLocations locations: AnyObject[]!) {
locationReceived = true
}
func locationManager(manager: CLLocationManager!, didFailWithError error: NSError!) {
locationReceived = false
}
我也尝试过在函数前面使用@optional,但是 Xcode 会引发编译器错误。有什么想法吗?
【问题讨论】:
-
您的代码似乎对我有用,您是否收到对话框询问您的应用是否可以使用您的位置?
-
@voidref 既然你提到了它,我就没有得到对话框。这有点奇怪......我刚刚检查了设置,并且该应用也获得了位置访问权限。
标签: cllocationmanager swift ios8