Alert view disappears on its own when calling [locationManager requestWhenInUseAuthorization];

You’re probably being ARC’d. Make sure that you still have a reference to your CLLocationManager. You can easily do this by making it a property.

ARC stands for Automatic Reference Counting. In an ARC-enabled project (and unless you are working on something really old or you turned it off on purpose, your project is an ARC-enabled project) you need to keep references to objects that you’ll use later on. CLLocationManager doesn’t return a singleton so you need to keep a reference to it in your classes that care. Something like this:

@property (strong, nonatomic) CLLocationManager *locationManager

See Apple’s ARC documentation for details. (And thanks Falko for hunting down the deep link to that.)

I’m putting Gobe’s comment inline in case you didn’t scroll to read it.

For Swift: instead of creating a local scope locationManager object,
let it as a property of your classes that care, like private let
locationManager = CLLocationManager() and then use it normally as
self.locationManager.requestWhenInUseAuthorization()

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)