【发布时间】:2017-05-16 18:04:06
【问题描述】:
我有一个应用程序可以根据用户的位置显示一些数据。它在 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 中启用了隐私 - 始终位置使用说明和隐私 - 使用时位置使用说明。为了测试我的代码,我还尝试调用 requestLocation,它也应该启动 didUpdateLocations,但它没有。也许我遗漏了一些东西,但对于 iOS10 的 CLLocationManager 处理似乎没有任何改变。
UPD:更多代码
class HomeViewController: BaseViewController, CLLocationManagerDelegate {
var locationManager = CLLocationManager()
var updatingLocation = true
//other stuff
}
【问题讨论】:
-
你是移动还是模拟移动>1Km?
-
刚刚尝试模拟静态位置和运动,并且正在呈现数据,但是,我不知道为什么没有模拟就不再有效。
-
也许用您的新信息编辑问题。问题似乎是“CLLocationManager 不报告iOS10下的初始位置”
-
已编辑问题
标签: swift swift3 cllocationmanager ios10