Search code examples
ioslocationcore-locationios11xcode9

Location access - App is not asking for user permission to access location - iOS 11


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


Solution

  • 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