Reputation: 1742
I'm having strange problem with UITableViewController. I'm requesting location service authroization inside viewDidLoad method, and I could see alertbox appear. However, this alertbox stays appear for couple of seconds then disappears. Why is this happening?
override func viewDidLoad() {
let locationManager = CLLocationManager()
locationManager.requestAlwaysAuthorization()
}
I tried this code inside the UIViewController that loads this UITableViewController and encountered different problem. This time, only push notification service request alertbox is displayed and location service request is entirely ignored. I'm guessing it is because push notification service request is not from me but from ios, and my location service request got overwritten by the ios notification request. It's my assumption correct or is there any explination for this behaviour?
Upvotes: 0
Views: 34
Reputation: 535989
Your location manager is going out of existence because it is a local variable. Make it a persistent property:
let locationManager = CLLocationManager()
override func viewDidLoad() {
// ...
}
Also I'm not sure whether it's a good idea to do this in viewDidLoad
. The view is not yet in the interface; in fact, there may be no interface yet.
But there are a lot of other things wrong with your code. You may already have authorization, or authorization may already have been denied, in which case there is no point requesting it. In general authorization requests are a much more elaborate business than your simple-minded code makes out.
Upvotes: 1