mapbox / DEPRECATED-mapbox-ios-sdk

REPLACED – use https://www.mapbox.com/ios-sdk instead
https://github.com/mapbox/mapbox-gl-native
Other
323 stars 8 forks source link

Cannot get requestWhenInUseAuthorization to work #519

Open esisa opened 9 years ago

esisa commented 9 years ago

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 commented 9 years ago

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.

esisa commented 9 years ago

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 commented 9 years ago

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

esisa commented 9 years ago

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 commented 9 years ago

Did you add the NSLocationWhenInUseUsageDescription to your info.plist?

    <key>NSLocationWhenInUseUsageDescription</key>
    <string>String shown in the alertview</string>
joaosobrinho commented 9 years ago

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 commented 9 years ago

Yes, I have added that.

Espen

  1. 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 https://github.com/mapbox/mapbox-ios-sdk/issues/519#issuecomment-60246622 .

incanus commented 9 years ago

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

Which example app @joaosobrinho?

joaosobrinho commented 9 years ago

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

wasatchtechnology commented 9 years ago

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 commented 9 years ago

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 commented 9 years ago

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

martinjbaker commented 9 years ago

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

incanus commented 9 years ago

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

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