位置权限弹出的回调没有被调用

Callback of location permission popup not get called

我已经创建了 CLLocationManager

的包装 class
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){---}