sam*_*ael 8 macos cllocationmanager swift
我正在使用CLLocationManager在swift 3中编写一个OSX应用程序,根据文档和我发现的所有示例应该没问题(这是一个类中的一个CLLocationManagerDelegate)
if CLLocationManager.locationServicesEnabled() {
let lm = CLLocationManager()
lm.requestWhenInUseAuthorization()
lm.delegate = self
lm.desiredAccuracy = kCLLocationAccuracyNearestTenMeters
lm.startUpdatingLocation()
print("should start getting location data")
} else {
print("Location service disabled");
}
Run Code Online (Sandbox Code Playgroud)
但似乎requestWhenInUseAuthorization(和requestAlwaysAuthorization)似乎不适用于OSX.我目前有这些函数调用包裹在#if块中:
#if os(macOS)
// can't find way for MacOSX to request auth
#endif
#if os(watchOS) || os(tvOS)
lm.requestWhenInUseAuthorization()
#endif
#if os(iOS)
lm.requestAlwaysAuthorization()
#endif
Run Code Online (Sandbox Code Playgroud)
那么有谁知道如何在macOS桌面应用程序中使用它?
| 归档时间: |
|
| 查看次数: |
747 次 |
| 最近记录: |