如何设置 macOS 的 CoreLocation 使用说明?

Nat*_*ate 6 macos info.plist core-location location-services

我正在尝试设置当我的应用程序请求位置授权时显示的字符串。我尝试在 Info.plist 中设置所有四个可能的键

NSLocationUsageDescription
NSLocationAlwaysUsageDescription
NSLocationWhenInUseUsageDescription
NSLocationAlwaysAndWhenInUseUsageDescription
Run Code Online (Sandbox Code Playgroud)

我还尝试设置在 iOS 中不推荐使用的locationManager.purpose字符串,但在 macOS 中不推荐使用。当应用程序请求授权时,这些方法都不会导致该字符串出现在警报中。

我正在使用此代码来请求访问权限:

    var locationManager = CLLocationManager()

    func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
        switch status {
        case .notDetermined:
            locationManager.startUpdatingLocation()
            locationManager.stopUpdatingLocation()
        default: break
        }
    }
Run Code Online (Sandbox Code Playgroud)

这是警报的屏幕截图:

在此输入图像描述

Calendar.app 能够自定义警报:

在此输入图像描述

Nat*_*ate 5

macOS 上正确的位置使用描述似乎是NSLocationUsageDescription(隐私 - 位置使用描述)。事实证明,我的设置是正确的,但 CoreLocation 一定已经缓存了该字符串(或缺少该字符串)。可能需要一天的时间才能最终决定使用新字符串,因为即使重新启动似乎也不会改变任何东西。您应该能够通过更改应用程序的捆绑标识符来绕过缓存来测试新字符串。

  • 我向 Apple DTS 询问了此事。他们建议您可以通过终端命令 tccutil Reset CoreLocationAgent 绕过缓存,然后重新启动计算机 (2认同)