I am in the process of learning iOS 8 app development with Swift. I have followed a tutorial on Treehouse that walks you through building a weather app in Swift and iOS 8.>
A couple of observations:
As you point out, if you're going to call requestAlwaysAuthorization
, then you must set NSLocationAlwaysUsageDescription
. If you called requestWhenInUseAuthorization
, you'd need NSLocationWhenInUseUsageDescription
. (The fact that you see the confirmation dialog means that you've done this correctly. I assume you are seeing whatever description you supplied in the confirmation alert.)
On your simulator, you may not see location updates like on a device. Test this on an actual device.
When I used your code, I see didUpdateLocations
when I called this from a device, but not from the simulator.
Once you solve the issue of not seeing didUpdateLocations
being called, there is another issue:
You are posting a notification when the authorization status changes, but not when a location is received asynchronously (i.e. later). Frankly, the latter is the more critical event from the view controller's perspective, so I would have thought that (a) you should post a notification when the location is received; and (b) the view controller should observe this notification. Right now, even if you succeed in getting didUpdateLocations
to be called, the view controller won't be notified of such.
Also, your didUpdateLocations
is initiating yet another asynchronous process, the geocode of the coordinate. If your view controller needs that, too, you should post a notification inside the completion block of the geocoder.
Frankly, you haven't even shown us the view controller code that adds an observer for whatever notifications that this CLLocationManagerDelegate
code will invoke, but I assume you have done that.