核心位置在模拟器Xcode 9.4.1中不起作用



我有以下代码:

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中的模拟器。我在这里错过了什么?

问题是func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!)已经过时了好几年。更新现代 Swift 的代码。声明的外观如下:

https://developer.apple.com/documentation/corelocation/cllocationmanagerdelegate/1423615-locationmanager

最新更新