Reputation: 386
I have a weird bug happening in an iOS app I am developing (Objective C). I am using location services inside an object that is created and stored as an instance variable of the root view controller class. This object is initialized in the viewDidLoad method.
if (sunEventObject == nil) {
sunEventObject = [[SunEvent alloc] init];
}
[sunEventObject updateLocation];
I have been running into the issue that the app does not request the location services on first launch of the app. I have run the app on my device while debugging with Xcode and a breakpoint set on the
[locationManager requestAlwaysAuthorization];
line. This line exists in the SunEvent class in a method designated for refreshing the location. This line of code executes, but the app does not request location service permissions.
As a workaround I placed this code in my AppDelegate file in the didFinishLaunchingWithOptions method.
CLLocationManager *locationManager = [[CLLocationManager alloc] init];
[locationManager requestAlwaysAuthorization];
This workaround works most of the time now, but occasionally on first launch (fresh download of the app), location services are still not being requested.
I have no idea what the issue could be. Again, the code is being executed (I know because of debugging the app with Xcode) but the app just isn't requesting location services like it should be doing.
NOTE This app is being developed for iOS 8.x systems only.
Update The info.plist file has the correct keys and description for the NSLocationAlwaysUsageDescription key, so that should not be the issue.
Upvotes: 0
Views: 168
Reputation: 386
Thanks to matt, his answer worked. My bug is fixed!
His comment: "See my answer here summarizing the correct logic that you must follow: stackoverflow.com/a/30495310/341994"
Upvotes: 1