macOS - 我在提示时拒绝了定位服务,现在弹出窗口不会再显示

macOS - I denied location services when prompted, and now the pop up won't show again

我正在使用 Swift 3 在 XCode 上开发一个 macOS 应用程序,我正在获取用户的位置。当应用程序第一次加载时,它会显示一个提示,询问用户是否允许访问他们的位置。自从我制作应用程序以来它一直在工作,但后来我更改了项目的名称,当我重新 运行 应用程序时再次显示弹出窗口时,我单击 "Cancel" 进行测试,现在当我再次尝试获取用户的位置时,弹出窗口不显示请求许可。

我检查了系统偏好设置 -> 安全和隐私 -> 隐私,但我的应用程序无法重新启用位置服务。

有什么想法吗?

下面的代码是我获取用户位置的方式,我在 viewDidLoad() 中调用它:

locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.startUpdatingLocation()

如果应用程序无法找到您的位置,这意味着您没有授予该应用程序使用您的位置的权限(很明显)。按照以下说明重置它以再次请求您的许可。

  1. Open a terminal and sudo to a root shell $ sudo -s

  2. Go to locationd/ $ cd /var/db/locationd

  3. Make a backup of clients.plist just in case $ cp -p clients.plist clients.plist.save

  4. Convert clients.plist to XML $ plutil -convert xml1 clients.plist

  5. Open the clients.plist and remove the entire that contains the Map My Route application, then save it.

  6. Convert the clients.plist back to binary $ plutil -convert binary1 clients.plist

  7. Restart locationd $ killall locationd