Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/99.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 尝试获取用户位置(swift)时出错_Ios_Swift_Xcode_Cllocationmanager - Fatal编程技术网

Ios 尝试获取用户位置(swift)时出错

Ios 尝试获取用户位置(swift)时出错,ios,swift,xcode,cllocationmanager,Ios,Swift,Xcode,Cllocationmanager,我正在尝试获取用户在iOS上的位置。 我使用CLLocationManagerDelegate来实现它 if CLLocationManager.locationServicesEnabled() { locationManager.delegate = self locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters locationManager.requestLocation() }

我正在尝试获取用户在iOS上的位置。 我使用
CLLocationManagerDelegate
来实现它

if CLLocationManager.locationServicesEnabled() {
    locationManager.delegate = self
    locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters
    locationManager.requestLocation()
}

func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
    let location = locations.first
    print("locations = \(location?.coordinate.latitude) \(location?.coordinate.longitude)")
}
但是我得到了这个错误

2017-03-24 18:03:57.183***在-[CLLocationManager requestLocation]中的断言失败, /BuildRoot/Library/Caches/com.apple.xbs/Sources/CoreLocationFramework\u Sim/CoreLocation-2100.0.34/Framework/CoreLocation/CLLocationManager.m:867
2017-03-24 18:03:57.194***由于未捕获的异常“NSinternalinconsistenceexception”而终止应用程序, 原因:“代理必须响应locationManager:didFailWithError:”

实施
locationManager:didFailWithError:

func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
    print(error.description)
}
我有这个警告

实例方法“locationManager(:didFailWithError:)”几乎与可选要求“locationManager(:didFailWithError:)”匹配 “CLLocationManagerDelegate”协议的

还有这个错误

***由于未捕获异常“NSInternalInconsistencyException”而终止应用程序, 原因:“代理必须响应locationManager:didFailWithError:”

我不知道什么是不正确的<代码>位置管理器:didFailWithError:已实现,但我有相同的错误

更改为

@objc(locationManager:didFailWithError:)
func locationManager(_ manager: CLLocationManager, didFailWithError error: NSError) {
    print(error.localizedDescription)
}

他们说这是8.1 xcode中的一个bug。你的xcode版本是什么。也许你需要更新。你对locationManager的定义是什么?@hasan83我有xcode 8.2。1@C6Silver让locationManager=CLLocationManager()是从NSObject继承的包含类吗?从NSObject继承后,我可以在没有警告的情况下构建它。所以现在没有崩溃吗?@hasan83是的,没有崩溃,但我仍然有这个警告