Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 928
Alok Avatar asked Sep 21 '17 06:09

Alok


1 Answers

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

like image 140
Alok Avatar answered Sep 19 '22 12:09

Alok