我的 Swift 应用程序中有 CoreLocation。当我在模拟器或设备中运行它时,会崩溃并且不会显示访问 CoreLocation 的权限。我拥有实现此功能所需的所有代码:代码请求,plist 中的 NSLocationWhenInUseUsageDescription 或 NSLocationAlwaysUsageDescription ... 我正在阅读 iOS app doesn't ask for location permission但我不能让这个节目。
var location: CLLocationManager!
let status = CLLocationManager.authorizationStatus()
location=CLLocationManager()
if(status == CLAuthorizationStatus.NotDetermined) {
self.location.requestAlwaysAuthorization();
}
else {
location.startUpdatingLocation()
}
location.delegate = self
location.desiredAccuracy=kCLLocationAccuracyBest
self.location.startMonitoringSignificantLocationChanges()
print(location.location.coordinate.latitude) //Here crash
print(location.location.coordinate.longitude)
我还能做些什么来展示这个?
谢谢!
最佳答案
这是我的应用程序中的代码片段:
let locationManager = CLLocationManager()
...
locationManager.delegate = self
locationManager.activityType = CLActivityType.Fitness
locationManager.distanceFilter = 10 // 10m
if ( UIDevice.currentDevice().systemVersion == "8.0" ) {
locationManager.requestAlwaysAuthorization()
}
// get current location
if CLLocationManager.authorizationStatus() == CLAuthorizationStatus.Authorized {
locationManager.startUpdatingLocation()
}
关于swift - 不请求访问 coreLocation 的权限并 swift 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25168318/