DEPRECATED-mapbox-ios-sdk icon indicating copy to clipboard operation
DEPRECATED-mapbox-ios-sdk copied to clipboard

Cannot get requestWhenInUseAuthorization to work

Open esisa opened this issue 11 years ago • 14 comments

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];
}```

esisa avatar Sep 30 '14 10:09 esisa

Where are you adding this code @esisa? See https://github.com/mapbox/mapbox-ios-sdk/commit/8d6b14a9a8463a80b6aff96a2d22df0648d41ca0 where I think we've taken care of this in the latest couple releases.

incanus avatar Sep 30 '14 16:09 incanus

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

esisa avatar Sep 30 '14 17:09 esisa

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

incanus avatar Oct 01 '14 23:10 incanus

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.

esisa avatar Oct 03 '14 07:10 esisa

Did you add the NSLocationWhenInUseUsageDescription to your info.plist?

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

phschneider avatar Oct 23 '14 14:10 phschneider

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.

joaosobrinho avatar Oct 24 '14 14:10 joaosobrinho

Yes, I have added that.

Espen 23. okt. 2014 16:25 skrev "Philip Schneider" [email protected] 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 https://github.com/mapbox/mapbox-ios-sdk/issues/519#issuecomment-60246622 .

esisa avatar Oct 24 '14 14:10 esisa

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

Which example app @joaosobrinho?

incanus avatar Oct 24 '14 17:10 incanus

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

joaosobrinho avatar Oct 24 '14 20:10 joaosobrinho

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

wasatchtechnology avatar Nov 21 '14 19:11 wasatchtechnology

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];
}

martinjbaker avatar Mar 02 '15 15:03 martinjbaker

This should be working fine. Check that the develop branch maybe helps resolve your problem (as of commit https://github.com/mapbox/mapbox-ios-sdk/commit/5703eb138bd406ffe8f6677365cefc99f78e379c).

incanus avatar Mar 02 '15 16:03 incanus

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

martinjbaker avatar Mar 03 '15 12:03 martinjbaker

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

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

incanus avatar Mar 03 '15 16:03 incanus