Independent watch app / CLLocationManager

Hi,


I'm working on an independent watch app that needs access to the user's current location.


I notice some general non-workiness in Beta 2 and now Beta 3:


  • `CLLocationManager.authorizationStatus()` always returns `.notDetermined` whenever the app starts up. My choice is not stored.
  • after providing it with the requested whenInUse authorization, the delegate's didChangeAuthorization method is called at which point I call either startUpdatingLocation or requestLocation, but no matter what I do, no further delegate methods will be called.


Does anybody else have similar issues?

Replies

I narrowed this down a bit:


in


func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus)


if I log both the new status and the global status, I get differing results:


func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus) {
    print("status changed: \(status.rawValue)")
    print("manager status: \(CLLocationManager.authorizationStatus().rawValue)")
}


will log


status changed: 4
manager status: 0


What's also interesting: I've compiled Apple's old Potloc sample, enabling the watch app to be able to run standalone. In that sample app, this actually works correctly and above log output would be


status changed: 4
manager status: 4


what doesn't make sense to me: The actual code between apple's sample and mine is identical, so this must be related to something in the Project itself. I have also tried changing the Deployment Target of the sample app to watchOS6, but still: It works there and it doesn't if I create a new project and use the code from apple's sample.


Does anybody know what's going on here?

ok. I can reliably reproduce the issue and I think it's a bug:


The difference is in the WatchKit Extension's .plist.


Given otherwise identical code, the erroneous behaviour only happens when


WKWatchOnly


is set.


In apple's sample code, when you tick the "allow to run standalone" checkbox, info.plist will have a different key set:


WKRunsIndependentlyOfCompanionApp


The former causes the erroneous behaviour, the latter is fine.


Filed in the Feedback Assistant as FB6465641

Did you managed to add

WKRunsIndependentlyOfCompanionApp

?

I'm getting an error


error: The value of WKCompanionAppBundleIdentifier in your WatchKit app's Info.plist "" does not match the bundle identifier of your companion app "com.[...].watch". (in target '[...] watch')


After setting it I get


The WKWatchOnly key must be present in your WatchKit extension's Info.plist and set to YES in order to mark it as a standalone WatchKit app.

So I'm back to the start.


This is my report FB6600744

Did you try setting WKRunsIndependentlyOfCompanionApp in both the Extension's and App's plist?

Congratulations on being actually able to test on the watch, btw. I was able to install my app once (with the same behavior as described) but now it wont even install… Going through my second day of rebooting everything over and over again, resetting the watch, etc… Fun times…