iPhone 5 and iOS 8 - Location permissions

Asked

Viewed 349 times

0

On all devices is OK, the request for permission to use the location appears (independent iOS 7 or iOS 8). Only iPhone 5 does not appear.

Code for requesting permission:

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 declared the Nslocationalwaysusagedescription key "We need your location"

  • iPhone 5 with iOS 8 or 7? Your access to the location is denied? Also see if your app is already listed on Ajustes > Privacidade > [Nome do seu app]

  • It is not listed, and does not show the dialog for requesting permission.

  • But is iOS 8? Your access is denied?

  • is iOS 8. On iOS 8 and 7 it makes the permission request, only on iPhone 5. On iPad, and on 6 it makes the question.

  • You have already added the key NSLocationWhenInUseUsageDescription in your Info.plist?

  • Yes, I added: Nslocationalwaysusagedescription as Boolean type with true value

  • NSLocationAlwaysUsageDescription must be a value String. This description will appear to the user at the time the permission is requested.

  • Right, just this key? No more?

  • Take a look at my answer and see if it helps you.

Show 4 more comments

1 answer

1


In iOS 8, before you can use Corelocation you must call the function requestAlwaysAuthorizationfor use in the foreground or requestWhenInUseAuthorization for use in the background.

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

You should call as follows:

Barter requestWhenInUseAuthorization for requestAlwaysAuthorization if you are asking for permission to use the background.

Swift:

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

Objective-C:

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

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

For use in the foreground:

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

For use in the background

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

If you do not add these keys happens exactly what you are describing: nothing appears.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.