gpt4 book ai didi

swift - 不请求访问 coreLocation 的权限并 swift 崩溃

转载 作者:行者123 更新时间:2023-11-28 09:20:24 27 4
gpt4 key购买 nike

我的 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/

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