Hi,
I'm having trouble reconciling the behaviour I'm seeing when requesting location authorization from the Watch Extension with the information provided at WWDC's What's New in Core Location session.
Here's what's happening (this assumes a new install of the app):
- In the watch extension, if I call CLLocationManager.requestAlwaysAuthorization(), the CLManageDelegate's locationManager(manager:didChangeAuthorizationStatus:) is called with .NotDetermined.
- The authorization UI appears on the Watch and iPhone as described during the session, using the iPhone's info.plist's NSLocationAlwaysUsageDescription value for the phone's prompt. The watch shows a message to check the phone with a Dismiss button, as expected.
- If I authorize on the phone, the watch 's message auto-dismisses (great!) but the watch does not receive another didChangeAuthorizationStatus: message with updated authorization.
Now…
- If I subsequently check the status on the phone, it's .AuthorizedAlways.
- If I subsequently check the status on the watch, it's .NotDetermined.
I thought that authorization state was synced to be the same on Watch and Phone. I understand that Watch itself doesn't do background location, but I thought the state should reflect the overall unified Phone+Watch status.
My workaround right now is this:
- Call CLLocationManager.requestAlwaysAuthorization() on the watch (step 1 above).
- When the watch received .NotDetermined, send a Message to the phone to request authorization.
- The phone receives the message and calls CLLocationManager.requestAlwaysAuthorization() (note the authorization UI may already be up from when this was requested from the watch, but this is OK).
- When the authorization is approved, the Phone received a delegate notification and updates the WatchConnectivity ApplicationState with a value saying that AuthorizedAlways has been granted. So now the watch knows.
- Note: When the watch wakes up and notices the ApplicationContext has changed to signal AuthorizedAlways is true, just for the **** of it I call requestAlwaysAuthorization() again on the watch, but the delegate doesn't get called at all at this point.
Is this a bug? Shouldn't the watchOS2's CLLocationManager report .AuthorizedAlways once it's been authorized on the phone?
And why is the second call to requestAlwaysAuthorization() in the last bullet above not responded to by the CLLocationManager?
Cheers,
Nick.