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

Alo*_*lok 7 location core-location ios ios11 xcode9

描述

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

完美地工作到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])
    {


    }
Run Code Online (Sandbox Code Playgroud)

Plist截图 在此输入图像描述

背景模式

在此输入图像描述

Alo*_*lok 14

我已经浏览了Apple文档并找到了这个问题的解决方案.

Apple已经改变了一些指导方针来获取用户位置.

以下是视频链接:Apple-位置技术的新功能

Swift和Objective-C中的位置访问的完整代码

解:

现在我们需要在Plist中添加三个身份验证密钥:

  1. NSLocationAlwaysAndWhenInUseUsageDescription
  2. NSLocationWhenInUseUsageDescription
  3. NSLocationAlwaysUsageDescription

Plist看起来像: 在此输入图像描述 身份验证消息屏幕将如下所示:

在此输入图像描述

位置访问的完整代码