【发布时间】:2018-08-29 22:57:30
【问题描述】:
我有以下代码:
import CoreLocation
class ViewController: UIViewController, NetworkingDelegate, CLLocationManagerDelegate {
let locationManager: CLLocationManager = CLLocationManager()
然后:
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestWhenInUseAuthorization()
locationManager.startUpdatingLocation()
然后我在 VC 中实现委托方法
func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) {
for currentLocation in locations{
print("\(index)\(currentLocation)")
}
print("Did Location Delegate get called?")
let location: CLLocation = locations.first as! CLLocation
print(location)
self.lat = String(format: "%f", location.coordinate.latitude)
self.long = String(format: "%f", location.coordinate.longitude)
}
在构建阶段,“Link Binary With Libraries”选择了 CoreLocation.framework。
存在 plist 中的正确隐私:隐私 - 位置使用说明与隐私 - 使用时的位置使用说明一样。
仍然没有得到位置。我在针对 iOS 11 的 Xcode 9.4.1 中使用模拟器。我在这里缺少什么?
【问题讨论】:
-
您必须开启 LOC。在 XCODE 模拟器选项中!! 太烦人了。 stackoverflow.com/a/32887820/294884
标签: ios core-location