0

I am trying to get my current location. My GPS is working and getting current location in all iOS devices expect iPhone X? Why I am not getting current location in iPhone X only? I am using iPhone X simulator for testing.Is it simulator bug or do I have to make any change in my code?

Here is my code. Hope you understand my problem. Thanks in advance.

<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)")
   }
}
M Reza
  • 18,350
  • 14
  • 66
  • 71
John
  • 3,769
  • 4
  • 12
  • 23

2 Answers2

0

Did you call locationManager.startLocationUpdates() function anywhere in your code? If not, then add this line where you have allocated location manager or called it in didChangeAuthorization when you get .authorizedWhenInUse status.

It is required to call locationManager.startLocationUpdates() to get location updated data.

Pratik Patel
  • 1,393
  • 12
  • 18
  • What was that method? Value of type 'CLLocationManager' has no member 'startLocationUpdates' , do you mean locationManager.startUpdatingLocation()? – John Apr 19 '18 at 06:00
  • Yes, locationManager.startUpdatingLocation() this method need to call. – Pratik Patel Apr 19 '18 at 06:04
  • I got the problem.I was denied location permission.so that i got all of this issues.can we programmatically ask for location permission if user denied permission first? – John Apr 19 '18 at 06:14
-1

I have same problem, but solution was very easy, delete your app from simulator iPhone X and rewrite again.

Andrew
  • 572
  • 6
  • 29
  • Thanks bro.I find the issue.I was denied location permission first.so that i got all of this issues. – John Apr 19 '18 at 06:15