Ios 无法在iPhone X Swift中获取当前位置

Ios 无法在iPhone X Swift中获取当前位置,ios,swift,geolocation,cllocationmanager,iphone-x,Ios,Swift,Geolocation,Cllocationmanager,Iphone X,我正在尝试获取我的当前位置。我的GPS正在所有iOS设备中工作并获取当前位置,除了iPhone X? 为什么我不能仅在iPhone X中获取当前位置? 我正在使用iPhoneX模拟器进行测试。这是模拟器错误还是我必须对代码进行任何更改 这是我的密码。 希望你能理解我的问题。提前谢谢 <key>NSLocationAlwaysAndWhenInUseUsageDescription</key> <string>Description</string>

我正在尝试获取我的当前位置。我的GPS正在所有iOS设备中工作并获取当前位置,除了iPhone X? 为什么我不能仅在iPhone X中获取当前位置? 我正在使用iPhoneX模拟器进行测试。这是模拟器错误还是我必须对代码进行任何更改

这是我的密码。 希望你能理解我的问题。提前谢谢

<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)")
   }
}
n位置始终和何时使用说明
描述
N位置始终使用说明
我们想知道你在哪里!
NSLocationWhenUse用途说明
我们想知道你的位置
扩展通知CenterViewController:CLLocationManagerDelegate{
func locationManager(\ manager:CLLocationManager,didChangeAuthorization状态:CLAuthorizationStatus){
如果状态==.authorizedWhenInUse{
locationManager.requestLocation()
}
}
func locationManager(manager:CLLocationManager,didUpdateLocations位置:[CLLocation]){
let userLocation:CLLocation=locations[0]
locationManager.StopUpdatengLocation()
让纬度=userLocation.coordinate.latitude
让经度=userLocation.coordinate.longitude
}
func locationManager(manager:CLLocationManager,didFailWithError:error){
//为什么我只在iPhoneX中出现这个错误。
打印(“错误::(错误)”)
}
}

我也有同样的问题,但解决方法很简单,从模拟器iPhone X中删除你的应用程序,然后重新编写

您是否在代码中的任何地方调用了
locationManager.startLocationUpdates()
函数? 如果没有,则将此行添加到您已分配位置管理器的位置,或在您获得
.authorizedWhenInUse
状态时在
didChangeAuthorization
中调用它


需要调用
locationManager.startLocationUpdates()
以获取位置更新数据。

错误是什么?错误域=kCLErrorDomain code=0”(null)“请参阅此项,谢谢。我试过了,但没有成功。我的应用程序在除iPhone X之外的所有设备和所有iOS版本的模拟器上都能正常工作。问题出在哪里?那是什么方法?“CLLocationManager”类型的值没有成员“startLocationUpdates”,您是指locationManager.startUpdatingLocation()?是,locationManager.startUpdatingLocation())此方法需要调用。我遇到了问题。我被拒绝了位置权限。因此,我遇到了所有这些问题。如果用户先拒绝了权限,我们可以通过编程方式请求位置权限吗?谢谢兄弟。我找到了问题。我先被拒绝了位置权限。因此,我遇到了所有这些问题。