I'm calling
[locationManager requestWhenInUseAuthorization];
on a screen that shows an MKMapView
(showsUserLocation = YES
). Which seems weird in the first place (Apple should handle this for MKMapView
automatically, but XCode was complaining when I didn't do it).
So I get the alert view that says the application wants to use your location, but then the alert view disappears on its own.
Why does the alert view disappear on its own?
Only thing I can think of is that I am calling requestWhenInUseAuthorization
in the initWithCoder
method. I'm only doing that because I think I saw the Xcode complaint when calling it from viewDidLoad.
When we don’t enable and configure our alert by hand, our coded alert simply doesn’t fire (TradingView Wiki, 2018). So coding the alertcondition () function in an indicator and then running that script on the chart is not enough. These are the steps to go from code to actual alert:
Next open up the ‘Create Alert’ window with the ‘Create Alert’ button (Alt + A). There select the alert condition that the indicator coded. Configure the other alert settings and then press ‘Create’ to activate it. TradingView (n.d.).
Open the ‘Create Alert’ window with a click on the ‘Create Alert’ button (Alt + A) in the chart’s toolbar. In that ‘Create Alert’ window select the alert condition coded by the indicator.
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()
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