使用位置管理器有一些問題。 看起來像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 –