Swift CLLocationManager不在iOS10下报告初始位置(未调用委托函数)

Swift CLLocationManager不在iOS10下报告初始位置(未调用委托函数),swift,swift3,cllocationmanager,ios10,Swift,Swift3,Cllocationmanager,Ios10,我有一个应用程序,可以根据用户的位置显示一些数据。它在Swift2和iOS9上运行良好。现在没有调用任何CLLocationManager委托函数。 这是我的密码: override func viewDidLoad() { super.viewDidLoad() locationManager.delegate = self //locationManager is being initialized at the top of class file and is no

我有一个应用程序,可以根据用户的位置显示一些数据。它在Swift2和iOS9上运行良好。现在没有调用任何CLLocationManager委托函数。 这是我的密码:

override func viewDidLoad() {
      super.viewDidLoad()
      locationManager.delegate = self //locationManager is being initialized at the top of class file and is not nil
       locationManager.requestAlwaysAuthorization()
       locationManager.desiredAccuracy = kCLLocationAccuracyKilometer
       locationManager.startUpdatingLocation() //This line executes from viewDidLoad, but not from delegate function
}


    func locationManager(_ manager: CLLocationManager, didDetermineState state: CLRegionState, for region: CLRegion) { //This is never called
            if CLLocationManager.authorizationStatus() != .authorizedWhenInUse {
                locationManager.requestWhenInUseAuthorization()
            }else{
                locationManager.startUpdatingLocation()
            }
        }

    func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) { //This is never called
        if updatingLocation == true { 
     //if location is updating, go next step
 }
}
我在我的Info.plist中启用了Privacy-Location Always Usage Description和Privacy-Location When Using Description。为了测试我的代码,我还尝试调用requestLocation,它也应该启动didUpdateLocations,但没有。也许我遗漏了一些东西,但似乎对于iOS10的CLLocationManager处理没有任何改变

UPD:更多代码

class HomeViewController: BaseViewController, CLLocationManagerDelegate {
var locationManager = CLLocationManager()
var updatingLocation = true
//other stuff
}

将所有
locationManager
委托函数从
viewDidLoad()
中取出:

还实施:

func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
    print("Failed: \(error.localizedDescription)")
}

查看您可能遇到的错误。

viewdiload()
中取出所有
locationManager
委托函数:

还实施:

func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
    print("Failed: \(error.localizedDescription)")
}

查看您可能遇到的错误。

抱歉,输入了一个错误-在实际代码中,它们已输出,但仍然无法工作。是否打印错误?此外,请显示您实例化CLManager的位置。不幸的是,它甚至从未出现错误,也没有打印任何内容。对不起,在实际代码中输入了一个错误-它们已输出,但仍不工作没有打印错误?此外,请显示您实例化CLManager的位置。不幸的是,它甚至从未出现错误,也没有打印任何内容。您是否移动或模拟移动>1Km?只是尝试模拟静态位置和移动,但数据正在显示,我不知道为什么这在没有模拟的情况下不再有效。也许可以用你的新信息编辑这个问题。问题似乎是“CLLocationManager未在iOS10下报告初始位置”编辑的问题您是否移动或模拟移动>1Km?只是尝试模拟静态位置和移动,但数据正在显示,我不知道为什么这在没有模拟的情况下不再有效。也许可以用你的新信息编辑这个问题。问题似乎是“CLLocationManager未在iOS10下报告初始位置”编辑的问题