The iOS dialog prompts and disappears after 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 don't know if this is relevant, but I'm using SWReavealViewController. Xcode9, compiled for iOS 8.0, both simulator and real device
Your locationManager
variable won't live beyond the scope of its definition (the function where that snippet of code lives), so it is deallocated before the user can respond to the dialog.
If you move let locationManager = CLLocationManager()
up to a class variable, it should stick around.
Insert let locationManager = CLLocationManager()
to the very beginning of the your ViewController
class. (Outside of viewDidLoad()
function). Hope it helps you.
class ViewController: UIViewController {
let locationManager = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With