In this chapter, we will have a look at some awesome updates to the
You want an optimized and energy-efficient way of requesting the current location of the user only once.
requestLocation() method of the
CLLocationManager class. The new location will be sent to your location manager’s
locationManager(_:didUpdateLocations:) delegate method. Errors will be reported on
locationManager(_:didFailWithError:). You can make only one request to this method at any given time. A new request will cancel the previous one.
Place a button on your interface inside IB and then hook it up to a method in your code called
requestLocation(). Then go into your Info.plist file and set the value of the
NSLocationWhenInUseUsageDescription key to a valid string that explains to the user why you want to get her location. You will also have to import the
CoreLocation framework and make your view controller conform to
Implement a variable in your view controller to represent the location manager:
When your button is pressed, request access to the user’s location. This requests users location to be delivered to your app only when it is the foreground app. As soon as ...