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

时间:2018-08-29 22:57:30

标签: ios core-location

我有以下代码:

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)
        }

在构建阶段,“将二进制文件与库链接”已选择CoreLocation.framework。

plist中存在适当的隐私权:隐私权-位置使用情况说明以及隐私权-使用时的位置使用情况说明。

该位置仍未得到。我正在针对iOS 11的Xcode 9.4.1中使用模拟器。我在这里缺少什么?

1 个答案:

答案 0 :(得分:0)

问题在于func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!)已过期。更新现代Swift的代码。声明的外观如下:

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

相关问题