7

Description

App is not asking for user permission to access location and getting state notDetermined

Working perfectly till iOS-10

var locationManager : CLLocationManager!

func getLocationDetails()
    {
        locationManager.delegate = self
        locationManager.desiredAccuracy = kCLLocationAccuracyBest
        locationManager.requestAlwaysAuthorization()
        locationManager.allowsBackgroundLocationUpdates = true
        locationManager.startUpdatingLocation()

    }

func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus)
    {
        if status == CLAuthorizationStatus.authorizedAlways || status == CLAuthorizationStatus.authorizedWhenInUse
        {
            locationManager.startUpdatingLocation()
        }
    }

    func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation])
    {


    }

Plist screenshot enter image description here

Background Modes

enter image description here

Alok
  • 24,880
  • 6
  • 40
  • 67

4 Answers4

18

I have gone through the Apple documentation and found the solution for this question.

Apple has changed few guidelines to get user location.

Here is the Video Link: Apple- What's New in Location Technologies

Full code for location access in Swift & Objective-C both

Solution:

Now we need to add three Authentication Key into Plist:

  1. NSLocationAlwaysAndWhenInUseUsageDescription
  2. NSLocationWhenInUseUsageDescription
  3. NSLocationAlwaysUsageDescription

Plist will look like : enter image description here And Authentication message screen will look like:

enter image description here

Full code for location access

Alok
  • 24,880
  • 6
  • 40
  • 67
  • your message should be informative otherwise apple will reject the app while reviewing. – Alok May 15 '18 at 05:03
  • Please make sure NSLocationAlwaysUsageDescription is also added otherwise you will get an error while uploading on the app store. – Alok May 17 '18 at 08:45
1

Please ask for the other permission also "When ever in use permission" and add both permission on the plist.

Ajay Singh Mehra
  • 1,313
  • 9
  • 19
  • +1 from iOS 11, you cannot have always as the only option for location, we MUST offer "when in use" option. – Harit K Sep 21 '17 at 07:17
-1

I've added both Keys in the info.plist file in order to ask for permissions, however after deleting the app and opened it again the simulator didn't display the alert to permit the user select one option.

I could make the alert appear again after deleting the app, then opening the settings application and finally installing again the app.

Hope it could help somebody.

-3

Please change requestAlwaysAuthorization to whenInUseAuthentication. Then it will start working. I think this might be due to GM Seed/Beta version of xcode. In stable version we might not have this issue.

B25Dec
  • 2,301
  • 5
  • 31
  • 54
  • This is not related to Authorization type. I am not using Beta version of Xcode. – Alok Sep 21 '17 at 06:56
  • I had same issue in xcode GM see while updating my app in iOS11. And making this changing it start showing alert to me on app installation. Hope it helps. Try once. – B25Dec Sep 21 '17 at 07:00