[英]Callback of location permission popup not get called
我確定了CLLocationManager
的包裝器類
public class MyLocationManager: NSObject, CLLocationManagerDelegate {
public static let shared = MyLocationManager()
var locationManager: CLLocationManager
override init() {
locationManager = CLLocationManager()
super.init()
locationManager.delegate = self
}
// function to request location “when-in-use” permission
public func requestWhenInUse() {
locationManager.requestWhenInUseAuthorization()
}
// callback of location permission popup
private func locationManager(_ manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus) {
//PROBLEM: it never get called
print(“Status: \(status)")
}
}
在我的UIViewController
之一中,我通過以下方法請求位置許可:
override func viewDidAppear(_ animated: Bool) {
MyLocationManager.shared.requestWhenInUse()
}
運行應用程序時,會出現位置權限彈出窗口,但是在允許或拒絕權限之后, MyLocationManager
的回調永遠不會被調用,為什么?
我以此為參考: https : //developer.apple.com/documentation/corelocation/cllocationmanagerdelegate/1423701-locationmanager
更新方法為最新語法
public func locationManager(_ manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus){---}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.