【发布时间】:2019-01-15 09:54:34
【问题描述】:
我想在从服务器收到推送通知时发送位置详细信息。但是 macOS 应用程序在启动时不会询问位置权限。在 info.plist 中添加了所有隐私项。它在调用 locationmanager.startUpdatingLocation() 时请求许可。并且没有再次询问我是否取消它。代码如下。
class AppDelegate: NSObject, NSApplicationDelegate, CLLocationManagerDelegate {
let locationManager = CLLocationManager()
func applicationDidFinishLaunching(_ aNotification: Notification) {
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
}
func scanLocationRequest{
locationManager.startUpdatingLocation()
// Call this when a notification receives.
}
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let currentLocation = locations.last
locationManager.stopUpdatingLocation()
sendLocationReport(currentLocation: currentLocation!)
}
}
【问题讨论】:
-
您的应用程序是否已添加到系统偏好设置的隐私窗格中?问题是什么?
标签: swift macos core-location cllocationmanager