A. Sola
A. Sola

Reputation: 117

Location in Simulator doesn't work. I get nil latitude and nil longitude

But when using a real device I obtain the right coordinates.

In simulator, I go to debug-Location-Custom Location or Apple but I always obtain nil values.

In real device two persons can use the app, that is, no nil values, but there's one third person that get crashes due nil values of coordinates.

In preferences, we all have activated the location services.

Upvotes: 0

Views: 228

Answers (1)

Lamour
Lamour

Reputation: 3030

Sometimes the simulator just wants to play game with your time :), so a total reset will do the trick.

However to prevent your app from crashing from the rule device or simulator, you should make sure you have complete access to the gps. so you should use didChangeAuthorizationStatus method.

func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus)
    {
        if status == CLAuthorizationStatus.Restricted
        {
           print(" Access Restricted \n")
        }
        else if status == CLAuthorizationStatus.Denied
        {
            print(" Access Denied \n")

        }
        else if status == CLAuthorizationStatus.AuthorizedAlways
        {
            self.MyLocationManager.startUpdatingLocation()  //<---- 
            print(" Access Granted \n")
        }
    }

As you could see when you have AuthorizedAlways then you want to start your gps.

Upvotes: 1

Related Questions