iOS13-WiFi-Info icon indicating copy to clipboard operation
iOS13-WiFi-Info copied to clipboard

Return value for CLLocationManager.authorizationStatus()

Open youseokhwan opened this issue 4 years ago • 0 comments

I need to detect network changes in background. But there was a problem when requesting location permission.

CLLocationManager.authorizationStatus() returns .authorisedAlways when the device is set to “While Using the App”

Maybe because I don't know iOS and Swift well. What's wrong?

override func viewDidLoad() {
    super.viewDidLoad()

    if #available(iOS 13.0, *) {
        let status = CLLocationManager.authorizationStatus()
            
        if status == .authorizedAlways {
            print("Always")
            startWifiDetection()
        } else if status == .authorizedWhenInUse {
            print("While Using the App")
            locationManager.delegate = self
            locationManager.requestAlwaysAuthorization()
        } else {
            print("Never or Ask Next Time")
            locationManager.delegate = self
            locationManager.requestWhenInUseAuthorization()
        }
    }
}

youseokhwan avatar Jan 18 '20 10:01 youseokhwan