位置的权限对话框显示并立即消失
问题描述:
iOS的对话框提示和消失后半秒:位置的权限对话框显示并立即消失
let locationManager = CLLocationManager()
switch CLLocationManager.authorizationStatus() {
case .authorizedWhenInUse:
print("In Use \(locationManager.location?.description)")
case .denied, .restricted:
print("denied")
case .notDetermined:
locationManager.requestWhenInUseAuthorization()
case .authorizedAlways:
print("always \(locationManager.location)")
}
我不知道这是否是相关的,但我使用SWReavealViewController。 Xcode9,编译为iOS 8.0,这两个模拟器和真实设备
答
你locationManager
变量不会活过它的定义(其中的代码片段居住功能)的范围,所以它被释放之前,用户可以响应到对话框。
如果你将let locationManager = CLLocationManager()
移动到一个类变量,它应该坚持下去。
该代码在哪里执行? – RaffAl
我在不同的地方尝试过 – gutte