Skip to content
This repository has been archived by the owner on May 9, 2018. It is now read-only.

Cannot get requestWhenInUseAuthorization to work #519

Open
esisa opened this issue Sep 30, 2014 · 14 comments
Open

Cannot get requestWhenInUseAuthorization to work #519

esisa opened this issue Sep 30, 2014 · 14 comments
Labels

Comments

@esisa
Copy link

esisa commented Sep 30, 2014

When testing out the SDK I cannot get requestWhenInUseAuthorization to work. No prompt is shown to the user to accept getting the location. I have added the necessary strings to the info.plist file.

To get it working I had to manually add this code:

self.locationManager = [[CLLocationManager alloc] init];

self.locationManager.delegate = self;

// Check for iOS 8. Without this guard the code will crash with "unknown selector" on iOS 7.
if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
    [self.locationManager requestWhenInUseAuthorization];
}```
@incanus
Copy link
Contributor

incanus commented Sep 30, 2014

Where are you adding this code @esisa? See 8d6b14a where I think we've taken care of this in the latest couple releases.

@incanus incanus added the bug label Sep 30, 2014
@esisa
Copy link
Author

esisa commented Sep 30, 2014

I have just added it into viewDidLoad in my own view controller.

I have the same problem using the weekend-picks-template and adding the same code there works too.
https://github.com/mapbox/weekend-picks-template-ios

@incanus
Copy link
Contributor

incanus commented Oct 1, 2014

@esisa Are you using the latest release? Can you submit some complete sample code that shows this problem?

@esisa
Copy link
Author

esisa commented Oct 3, 2014

I am running weekend-picks-template-ios with no changes from the current master branch. I have updated to the latest XCode.

Running on iOS7 simulators work just fine. Running it in iOS8 does not bring up the location prompt and the location button does not bring me to the location set in the simulator.

It is probably some quirk with my setup, but I have no idea what it would be.

@phschneider
Copy link

Did you add the NSLocationWhenInUseUsageDescription to your info.plist?

    <key>NSLocationWhenInUseUsageDescription</key>
    <string>String shown in the alertview</string>

@joaosobrinho
Copy link

I'm also having this issue.
The example app also doesn't show the user location on iOS8.1.

I have the NSLocationWhenInUseUsageDescription key on my info.plist

I'm using MapBox 1.4.1 installed as a binary.

@esisa
Copy link
Author

esisa commented Oct 24, 2014

Yes, I have added that.

Espen
23. okt. 2014 16:25 skrev "Philip Schneider" notifications@github.com
følgende:

Did you add the NSLocationWhenInUseUsageDescription to your info.plist?

<key>NSLocationWhenInUseUsageDescription</key>
<string>String shown in the alertview</string>

Reply to this email directly or view it on GitHub
#519 (comment)
.

@incanus
Copy link
Contributor

incanus commented Oct 24, 2014

The example app also doesn't show the user location on iOS8.1.

Which example app @joaosobrinho?

@joaosobrinho
Copy link

@incanus The app in this link: https://github.com/mapbox/mapbox-ios-example

@wasatchtechnology
Copy link

This sounds line my issue as well. I am not using CLLocationManager directly, the RMMapView does it all and I call:
mapView.showsUserLocation = TRUE;
mapView.userTrackingMode = RMUserTrackingModeFollow;
And then I would receive location updates from the MapView.

In looking through the code for 1.1.4 in RMMapView i see the NSAssert

// enable iOS 8+ location authorization API
if ([CLLocationManager instancesRespondToSelector:@selector(requestWhenInUseAuthorization)])
{
NSAssert([[[NSBundle mainBundle] infoDictionary] valueForKey:@"NSLocationWhenInUseUsageDescription"], @"For iOS 8 and above, your app must have a value for NSLocationWhenInUseUsageDescription in its Info.plist");
[_locationManager requestWhenInUseAuthorization];
}
This doesn't appear to be working as intended ??

@martinjbaker
Copy link

Broken for me too on iOS8+. Fortunately you can work around it with a dummy location manager

BOOL needToRequestAuthorization = [CLLocationManager instancesRespondToSelector:@selector(requestWhenInUseAuthorization)];
if (needToRequestAuthorization && !self.dummyLocationManager) {
    self.dummyLocationManager = [[CLLocationManager alloc] init];
    [self.dummyLocationManager requestWhenInUseAuthorization];
}

@incanus
Copy link
Contributor

incanus commented Mar 2, 2015

This should be working fine. Check that the develop branch maybe helps resolve your problem (as of commit 5703eb1).

@incanus incanus closed this as completed Mar 2, 2015
@martinjbaker
Copy link

That commit won't make any difference to my usage. I'm using NSLocationWhenInUseUsageDescription in the Info.plist as per original code.

@incanus
Copy link
Contributor

incanus commented Mar 3, 2015

This doesn't appear to be working as intended ??

Does your code break on this section if running on iOS 8 @wasatchtechnology?

@incanus incanus reopened this Mar 3, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

6 participants