【发布时间】:2017-01-12 15:55:39
【问题描述】:
这很奇怪。有一些设备会崩溃,而其他一些设备不会。问题是当没有激活位置时,应用程序永远不会死,但是当我允许我的应用程序访问某些设备中的位置时会崩溃,而在其他设备中则不会。
这是代码:
override func viewDidAppear(animated: Bool) {
if CLLocationManager.locationServicesEnabled(){
switch CLLocationManager.authorizationStatus() {
case .NotDetermined, .Restricted, .Denied:
print("No access")
case .AuthorizedAlways, .AuthorizedWhenInUse:
let geocoder = CLGeocoder()
longitude = self.locationManager.location!.coordinate.longitude
latitude = self.locationManager.location!.coordinate.latitude
geocoder.reverseGeocodeLocation(CLLocation(latitude: (latitude), longitude: (longitude)), completionHandler: {placemarks, error in
if error == nil && placemarks!.count > 0 {
self.thoroughfare = (placemarks!.last?.thoroughfare)!
self.city = (placemarks!.last?.locality)!
print(self.thoroughfare)
print(self.city)
print(self.longitude)
print(self.latitude)
}
})
}
} else {
print("Location services are not enabled")
}
}
当应用程序崩溃时,错误指向这一行:
longitude = self.locationManager.location!.coordinate.longitude
latitude = self.locationManager.location!.coordinate.latitude
我已经在 10 台设备上测试了该应用,其中有 1-2 台在此时崩溃。
发生了什么事?我认为我正确地管理了在允许或不允许位置时做什么和不做什么。
【问题讨论】:
标签: ios swift crash cllocationmanager