iPhone 5 and iOS 8 - Location Permissions

0

All devices are OK, the permission request for location usage (independent of iOS 7 or iOS 8) appears. Only the iPhone 5 does not appear.

Permission request code:

var versionString = UIDevice.currentDevice().systemVersion.stringByReplacingOccurrencesOfString(".", withString: "", options: NSStringCompareOptions.CaseInsensitiveSearch, range: nil) as NSString
    if versionString.floatValue >= 800 {
        if CLLocationManager.authorizationStatus() != CLAuthorizationStatus.Authorized && CLLocationManager.authorizationStatus() != CLAuthorizationStatus.AuthorizedWhenInUse {

            if CLLocationManager.authorizationStatus() == CLAuthorizationStatus.Denied {
                    NSLog("Not Accepted")
            } else {
                locationManager.requestAlwaysAuthorization()
            }
        }
    } else {
        if CLLocationManager.authorizationStatus() == CLAuthorizationStatus.Denied {
            NSLog("Not Accepted")
        } else {
            locationManager.startUpdatingLocation()
            locationManager.stopUpdatingLocation()
        }
    }

I declare the key NSLocationAlwaysUsageDescription "We need your location"

    
asked by anonymous 14.01.2015 / 18:00

1 answer

1

On iOS 8, before you can use CoreLocation you should call the requestAlwaysAuthorization function for foreground use or requestWhenInUseAuthorization for background use.

As these functions are only available from iOS 8, if you call any of them directly in iOS 7 your app will die with a unrecognized selector error.

You should call as follows:

Change requestWhenInUseAuthorization by requestAlwaysAuthorization if you are requesting background permission.

Swift:

if (locationManager.respondsToSelector(Selector("requestWhenInUseAuthorization"))) {
  locationManager.requestWhenInUseAuthorization()
}

Objective-C:

if ([locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
  [locationManager requestWhenInUseAuthorization];
}

You should also add the following keys in Info.plist of your project:

For foreground use:

<key>NSLocationWhenInUseUsageDescription</key>
<string>Mensagem que o usuário verá na janela de permissão</string>

For background use

<key>NSLocationAlwaysUsageDescription</key>
<string>Mensagem que o usuário verá na janela de permissão</string>

If you do not add these keys exactly what you're describing is happening: nothing appears.

    
14.01.2015 / 19:05