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

痴心易碎 提交于 2019-11-26 16:46:08

问题


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

Background Modes


回答1:


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 : And Authentication message screen will look like:

Full code for location access




回答2:


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




回答3:


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.




回答4:


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.



来源:https://stackoverflow.com/questions/46336530/location-access-app-is-not-asking-for-user-permission-to-access-location-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!