Ionic 3 - ios 11 - always ask for GPS location - ios

For the latest ios version on the iPhone, I'm not getting the 'always' for always track your location on the iPhone. I'm getting while on the app and never. However this functionality seems to be working fine for every version previous. Any other suggestions than what I've done in XCode below would be great.
CDVLocation.m
if([[NSBundle mainBundle] objectForInfoDictionaryKey:#"NSLocationAlwaysUsageDescription"]){
[self.locationManager requestWhenInUseAuthorization];
} else if([[NSBundle mainBundle] objectForInfoDictionaryKey:#"NSLocationWhenInUseUsageDescription"]) {
[self.locationManager requestAlwaysAuthorization];
} else {
NSLog(#"[Warning] No NSLocationAlwaysUsageDescription or NSLocationWhenInUseUsageDescription key is defined in the Info.plist file.");
}
in the plist file
<key>NSLocationAlwaysUsageDescription</key>
<string>This app requires constant access to your location in order to track your position, even when the screen is off.</string>

The code has the logic inverted, it should be this:
if ([[NSBundle mainBundle] objectForInfoDictionaryKey:#"NSLocationAlwaysUsageDescription"]){
[self.locationManager requestAlwaysAuthorization];
} else if([[NSBundle mainBundle] objectForInfoDictionaryKey:#"NSLocationWhenInUseUsageDescription"]) {
[self.locationManager requestWhenInUseAuthorization];
} else {
NSLog(#"[Warning] No NSLocationAlwaysUsageDescription or NSLocationWhenInUseUsageDescription key is defined in the Info.plist file.");
}
Notice I switched these two lines:
[self.locationManager requestAlwaysAuthorization];
[self.locationManager requestWhenInUseAuthorization];
You can refer to the master source code.
Additionally, for iOS 11, when requesting always permission you should include the NSLocationAlwaysAndWhenInUseUsageDescription and the NSLocationWhenInUseUsageDescription key in your info plist.
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>When always is requested in iOS 11</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>When "when in use" is requested in iOS 11</string>
You are required to include the NSLocationWhenInUseUsageDescription and NSLocationAlwaysAndWhenInUseUsageDescription keys in your app's Info.plist file. (If your app supports iOS 10 and earlier, the NSLocationAlwaysUsageDescription key is also required.) If those keys are not present, authorization requests fail immediately.

Related

Not being prompted to enable Location Services in App

UPDATE: THIS IS NOT A DUPLICATE. I have already added the required key to the info.plist as stated in my original question and the issue remains. I have tried all three keys in various combinations.
Before anyone gets upset, I have read through many Apple Dev forum posts and stack overflow posts and cannot figure out why my app refuses to prompt the user to allow When In Use authorization.
I've added the following key to my Info.plist file with an accompanying String value:
NSLocationWhenInUseUsageDescription
I've then written (both in Swift and Obj-C) the code that should prompt the user:
#property CLLocationManager *location;
...
#synthesize location;
...
location = [[CLLocationManager alloc] init];
location.delegate = self;
location.desiredAccuracy = kCLLocationAccuracyBest;
location.distanceFilter = kCLDistanceFilterNone;
[location requestWhenInUseAuthorization];
[location startUpdatingLocation];
I'm using the following CLLocationManagerDelegate methods.
- (void) locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
- (void) locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status
This was basically copied straight from the Apple "LocateMe" sample code.
No matter what various sequences or minor changes I try, the app never prompts to allow authorization. I've used a switch statement to determine the state of [CLLocationManager authorizationStatus], but continually recieve a "Not Determined" response.
if ([CLLocationManager locationServicesEnabled]) {
switch ([CLLocationManager authorizationStatus]) {
case kCLAuthorizationStatusAuthorizedAlways:
NSLog(#"Always Authorized");
break;
case kCLAuthorizationStatusDenied:
NSLog(#"Denied");
break;
case kCLAuthorizationStatusAuthorizedWhenInUse:
NSLog(#"Authorized in Use");
break;
case kCLAuthorizationStatusNotDetermined:
NSLog(#"Not Determined");
break;
case kCLAuthorizationStatusRestricted:
NSLog(#"Restricted");
break;
}
}
Any help would be greatly appreciated. I'm running Xcode 6.2 (6C101) with iOS 8.1.2 physical device and iOS 8.2 (12D5452a) simulator for testing.
I faced the exact same problem, after digging in for two days, it turned out that the app does not read from the info.plist file that is included in the bundle in project navigator's pane, because it has been localized to another language and base internationalization is being used, that means in Finder there will be 3 info.plist files:
1- under Tests folder
2- under base.lproj folder
3- under ar.lprj (ar refers to Arabic language).
the project reads from base.lproj's version which is not included inside the bundle in the project navigator's pane.
what I did is that I took a backup copy of the plist file that I want (number 2 above), and removed localization on the info.plist file that is inside project navigator and chose delete from disk to delete it completely, then I took the back up copy and placed in under project's root in Finder and import it back in Xcode, and now the project reads from the new info.plist file and the key NSLocationWhenInUseUsageDescription fires up the user authorization alert at app launch.
hope this helps.
If you have changed the Location Settings in your iPhone simulator this may cause the prompt to not show. For example, if you are already set the Location permissions via Allow Locations access iOS prompt and made a decision this is stored in the Privacy settings for the iPhone simulator and so subsequent calls to locationManager.requestAlwaysAuthorization() or locationManager.requestWhenInUseAuthorization() will not display the iOS prompt because you already have defined your Privacy -> Location Settings for your app.
To clear settings for an iPhone simulator: "iOS Simulator" -> "Reset Content and Settings..."
Also I did a Clean build in Xcode and quit and restarted the iPhone simulator at some point, I could be wrong about this part being of any help...
Lots of useful comparisons here: http://nevan.net/2014/09/core-location-manager-changes-in-ios-8/
Also, silly question time: you mix _location and self.location but you don't show your property/synthesize code. Are you sure you're operating on the same object?
I found that in your info.plst file you can't use the Privacy - Location Usage Description key, you have to have a key called NSLocationWhenInUseUsageDescription and a value. I was able to get your code working by adding this key into my info.plist
#import <MapKit/MapKit.h>
#interface ViewController ()
#property CLLocationManager * location;
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
_location = [[CLLocationManager alloc] init];
self.location.delegate = self;
self.location.desiredAccuracy = kCLLocationAccuracyBest;
self.location.distanceFilter = kCLDistanceFilterNone;
[_location requestWhenInUseAuthorization];
[self.location startUpdatingLocation];
}
It may be silly, but i just spent almost 2 hours double and triple checking all of the answers i could find about CLLocationManager permissions.
I felt stupid when i finally realized that i had 2 info.plist files and i was using the wrong one!
You can check in your project's build settings - there's a value called Info.plist File.
Just want to leave it here for future readers.

'-[CLLocationManager requestAlwaysAuthorization]: unrecognized selector sent to instance

Can anyone please help in getting fix for fetching location updates in ios8 xcode6 i am getting the crash at [locationManager requestAlwaysAuthorization];
if i place this line of code in
if ([locationManager respondsToSelector:#selector(requestAlwaysAuthorization)]) {
[locationManager requestAlwaysAuthorization];
}
then Locationmanager delegates are not called.
I was having the exactly same problems.
Then I figured that I ran it on the wrong device (wrong iOS)
locationManager requestAlwaysAuthorization
availability iOS 8.0 and later
That's it. Run it on iOS 8 or later. You better use check version to use that method.

Buzztouch geo location not working compiled in xcode 6

I upgraded to xcode 6, compiled a new app, discovered that the geo location is not working, and am searching for a work around.
There is no option in the phone's settings for the newly compiled app to choose a privacy/location services option "Never" or "always.
The older apps compiled in xcode5 still have this option.
UPDATE
Problem solved. Compiled in BT 3.0
- Added this code in BT_screen_customURL.m under the //appDelegate comment (line 64)
if ([appDelegate.rootLocationMonitor.locationManager respondsToSelector:#selector(requestAlwaysAuthorization)])
[appDelegate.rootLocationMonitor.locationManager requestAlwaysAuthorization];
Added these as string messages to info.plist
NSLocationAlwaysUsageDescription
NSLocationWhenInUseUsageDescription
Additonal informaton: https://www.buzztouch.com/forum/thread.php?tid=DA308929DBC29D1DB83B7A8&currentPage=1
Also, the link provided by Alberto below was helpful.
Your app is write in Objective C?
add the following lines:
kCLAuthorizationStatusAuthorizedAlways <- For background battery-killers.
kCLAuthorizationStatusAuthorizedWhenInUse <- For sensible apps.
in your plist
For more information: http://www.splinter.com.au/2014/09/14/ios8-corelocation/
Best,
Alberto

No visible #interface for 'CLLocationManager' declares the selector 'requestAlwaysAuthorization'

We are making an app to be compatible with iOS 8, but at the same time, some of our developers do not have Xcode 6 yet, so they are getting this error when trying to call
[self.locationManager requestAlwaysAuthorization];
Even if it is inside an if
if(floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_7_1) {
[self.locationManager requestAlwaysAuthorization];
}
How can we solve this to compile on Xcode 5?
The following is the proper way to deal with this. This assumes that your app has a "Deployment Target" of iOS 7.x or earlier and you need to compile the project with different values for the "Base SDK" (such as iOS 8 under Xcode 6 and iOS 7 under Xcode 5):
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000
// Being compiled with a Base SDK of iOS 8 or later
// Now do a runtime check to be sure the method is supported
if ([self.locationManager respondsToSelector:#selector(requestAlwaysAuthorization)]) {
[self.locationManager requestAlwaysAuthorization];
} else {
// No such method on this device - do something else as needed
}
#else
// Being compiled with a Base SDK of iOS 7.x or earlier
// No such method - do something else as needed
#endif
Accepted answer didn't work for my particular situation. Due to build enviroment limitations (Phonegap/Cordova) I'm stuck on compiling against the iOS7 SDK only.
I implemented the following (as suggested in comments):
if([self.locationManager respondsToSelector:#selector(requestAlwaysAuthorization)]) {
// Use performSelector: so compiler won't blow up on this
[self.locationManager performSelector:#selector(requestAlwaysAuthorization)];
}
It might show compiler warnings, but atleast it works in that specific case.

Cannot get user's location with NSLocationWhenInUseUsageDescription

I'm using Xcode 6 beta (6A215l). I've referred this question and updated my code to:
use NSLocationWhenInUseUsageDescription in the .plist file,
call requestWhenInUseAuthorization in the source code
but neither didUpdateLocations: nor didFailWithError: was called. If I use NSLocationAlwaysUsageDescription and requestAlwaysAuthorization, my app works.
Does anyone have the same problem? I wonder if I should try with Xcode 6 beta 2..
In fact, if you want to use the requestWhenInUseAuthorization in your app and gets the didUpdateLocations: and didFailWithError: delegate methods to be called, you need to set in your .plist file BOTH NSLocationAlwaysUsageDescription and NSLocationWhenInUseUsageDescription keys, to make it work.
Theses texts will then be displayed in the Settings/Privacy/Location Services/App section of your device.

Resources