gpt4 book ai didi

cocoa - Swift - CLLocationManager 不要求用户许可

转载 作者:可可西里 更新时间:2023-11-01 01:06:51 25 4
gpt4 key购买 nike

我正在使用 Xcode beta 2 并尝试使用 OS X 应用程序获取用户位置,但它甚至没有征求用户许可。这是我到目前为止所做的。

...
import CoreLocation

class AppDelegate: NSObject, NSApplicationDelegate, CLLocationManagerDelegate {

var locManager : CLLocationManager = CLLocationManager()

func applicationDidFinishLaunching(aNotification: NSNotification?) {
locManager.delegate = self
locManager.desiredAccuracy = kCLLocationAccuracyBest
locManager.startUpdatingLocation()
}

func locationManager(manager: CLLocationManager!, didUpdateToLocation newLocation: CLLocation!, fromLocation oldLocation: CLLocation!) {
//doSomething.
}

}

没有任何反应。我查看了其他问题并尝试了答案中所有建议的解决方案,但没有奏效。尝试使用 Objective-C,一切正常。我在这里遗漏了什么吗?

在计算机的首选项中启用了定位服务。 “NSLocationUsageDescription”也在 info.plist 中。 NSLocationWhenInUseUsageDescription 和 NSLocationAlwaysUsageDescription 用于 10.10 及更高版本,我正在使用 10.9。

Information Property List Key Reference

最佳答案

代码方面没有问题,只是注意到它是 App Sandbox 授权问题。一旦我检查了 App Data 下的 Location,它就立即起作用了。

enter image description here

关于cocoa - Swift - CLLocationManager 不要求用户许可,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24499530/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com