使用位置管理器有一些问题。 看起来像locationManager.requestWhenInUseAuth不会停止应用程序流,并且在用户可以解除身份验证警报之前调用startUpdatingLocation。 如何避免这种情况?CLLocationManager在用户授权之前开始更新Swift
我的应用程序加载了非可用GPS的默认值,所以我总是得到默认值(因为即使“想要认证此应用程序...?”警报仍然显示,此func被调用)。
我的代码:
if ask{
locationManager.requestWhenInUseAuthorization()
self.manageLocation()
}
func manageLocation(){
if CLLocationManager.locationServicesEnabled() {
switch(CLLocationManager.authorizationStatus()) {
case .notDetermined, .restricted, .denied:
// load default deck
self.loadBlink(useDefault: true)
case .authorizedAlways, .authorizedWhenInUse:
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters
locationManager.distanceFilter = 10.0
locationManager.startUpdatingLocation()
}
} else {
// load default deck
self.loadBlink(useDefault: true)
}
}
您是否在应用程序委托中放置了位置访问身份验证和startUpdatingLocation的代码? –
如果您之前已经获得许可,位置管理器将开始更新位置。 –
不,我应该吗? @HimanshuMoradiya –