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.


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 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.


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];
}
链接地址: http://www.djcxy.com/p/82986.html

上一篇: 如何在没有注释的情况下获取dygraph中显示的工具提示

下一篇: 不提示在App中启用位置服务