iOS 8 requestWhenInUseAuthorization no Popup

前端 未结 6 2013
名媛妹妹
名媛妹妹 2020-12-04 12:25

I tried to make my AppProject iOS 8 ready. I had read a lot about

[_locationManager requestWhenInUseAuthorization];

and the entry in plist<

6条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-04 12:38

    iOS 8.3, Xcode 6.3.1, ARC enabled

    The question has been resolved, but I have (2) notes to add from my recent involvement with CLLocationManager.

    1) You must have the following keys entered into your *.plist file:

    enter image description here

    Most commonly used keys have generic more descriptive names, such as "Privacy - Location Usage Description", which really is the "NSLocationUsageDescription" key.

    To see the "raw" key names go to "*-Info.plist" and right click in the Navigator area where the keys are listed, see below:

    enter image description here

    And you get the following results:

    enter image description here

    The three keys that are related to this article are:

    enter image description here

    2) Make certain that you allocate and initialize your implementation of CLLocationManager before you try to request authorization or update location.

    *.h file:

    @interface SomeController : UIViewController 
    
    @property (strong, nonatomic) CLLocationManager *locationManager;
    

    *.m file:

    - (IBAction)locationButton:(UIButton *)sender
    {
        if (self.locationManager == nil)
        {
            self.locationManager = [[CLLocationManager alloc] init];
            self.locationManager.delegate = self;
        }
        else
        {
            nil;
        }
    
        if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)])
        {
            [self.locationManager requestWhenInUseAuthorization];
        }
        else
        {
            nil;
        }
    
        self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
        [self.locationManager startUpdatingLocation];
    }
    

    Hope this saves someone time! Thanks.

提交回复
热议问题