0

I am coding in Swift and I want to use the user's location in my app. I have already added NSLocationWhenInUseUsageDescription and NSLocationAlwaysUsageDescription to Info.plist and have properly configured them. I have also added CoreLocation.framework and imported it in the ViewController. I am also using CLLocationManagerDelegate in my class definition. I have implemented the method didChangeAuthorizationStatus and this works when the user chooses to allow for their location to be given to the app. I have printed out text to console when this happens to make sure. However, when I call the method didUpdateLocations from this method right after printing to the console, the method does not run and nothing new is printed to console. I have made sure to include a print command in the didUpdateLocations method just to make sure of this. This is the code for one of the methods:

func locationManager(manager: CLLocationManager, didChangeAuthorizationStatus status: CLAuthorizationStatus) {
    if status == .AuthorizedWhenInUse {
        print("permission granted")
        locationManager.startUpdatingLocation()
    } else {
        print(status)
    }
}

As you can see, in the method, locationManager.startUpdatingLocation() is called and it is supposed to start doing that. Here is the code for this method:

func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
    print(locations)
}

However, once I press Allow in my app when it asks me, it doesn't print anything to the console besides "permission granted", which was called in the first method. How do I fix this? Any help is greatly appreciated!

EDIT:

Well, actually I just fixed the problem by simulating movement in the simulator phone. You just have to click Debug, hover over Location, and pick a form of movement!

0 Answers0