The location resolution window appears and disappears immediately

The iOS dialog box prompts and disappears in half a second:

        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)")
        }

I do not know how relevant this is, but I use SWReavealViewController. Xcode9 compiled for iOS 8.0, both a simulator and a real device

+4
source share
1 answer

Your variable locationManagerwill not go beyond its definition (the function in which this code fragment is located), so it is freed before the user can respond to the dialog.

If you move let locationManager = CLLocationManager()up to a class variable, it should stick.

+5
source

Source: https://habr.com/ru/post/1687830/


All Articles