位置访问 – 应用程序不要求用户访问位置的权限 – iOS 11

描述

应用程序不要求用户访问位置的权限,并获得状态未确定

完美工作,直到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截图 在这里输入图像说明

背景模式

在这里输入图像说明

我已经通过苹果文档,find了这个问题的解决scheme。

苹果已经改变了一些准则,以获得用户位置。

这里是video链接: 苹果 – 定位技术的新进展

解:

现在我们需要在Plist中添加两个authentication密钥:

  1. NSLocationAlwaysAndWhenInUseUsageDescription
  2. NSLocationWhenInUseUsageDescription

Plist将如下所示: 在这里输入图像说明

和身份validation消息屏幕将如下所示:

在这里输入图像说明

完整的位置访问代码

请另外请求“使用许可时”,并且在plist上添加双方的许可。

请在使用whenInUseAuthentication更改requestAlwaysAuthorization 。 然后它将开始工作。 我想这可能是由于xcode的GM Seed / Beta版本。 在稳定版本中,我们可能没有这个问题。