I have cerated a wrapper class of 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)")
}
}
In one of my UIViewController, I request location permission by:
override func viewDidAppear(_ animated: Bool) {
MyLocationManager.shared.requestWhenInUse()
}
When run app, location permission popup comes, but after allow or deny permission, the callback inside MyLocationManager never get called, why?
I take this as a reference: https://developer.apple.com/documentation/corelocation/cllocationmanagerdelegate/1423701-locationmanager