【发布时间】:2018-09-29 11:25:10
【问题描述】:
我正在尝试获取我当前的位置。我的 GPS 正在工作并在所有 iOS 设备(除了 iPhone X)中获取当前位置吗? 为什么我只在 iPhone X 中没有获得当前位置? 我正在使用 iPhone X 模拟器进行测试。是模拟器错误还是我必须对我的代码进行任何更改?
这是我的代码。 希望你能理解我的问题。提前致谢。
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>Description</string>
<key>NSLocationAlwaysUsageDescription</key>
<string>we want to know where you are!</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>we want to get your location</string>
extension NotificationCenterViewController : CLLocationManagerDelegate {
func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
if status == .authorizedWhenInUse {
locationManager.requestLocation()
}
}
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
let userLocation: CLLocation = locations[0]
locationManager.stopUpdatingLocation()
let latitude = userLocation.coordinate.latitude
let longitude = userLocation.coordinate.longitude
}
func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
// Why I am getting this error in only in iPhone X only.
print("error:: (error)")
}
}
【问题讨论】:
-
错误是什么?
-
错误域=kCLErrorDomain Code=0 "(null)"
-
谢谢。我试过了,但没有用。我的应用程序在所有设备和所有 iOS 版本的模拟器上都可以运行,除了 iPhone X。问题是什么?
标签: ios swift geolocation cllocationmanager iphone-x