WatchKit settings bundle in 2.0?

In the original WatchKit, one could set up a WatchKit settings bundle which would specify settings to be included in the app's page within the Apple Watch app.


The settings were written to a shared NSUserDefaults identified by an app group name.

The WatchKit extension would be given an App Groups entitlement to allow it to read the shared NSUserDefaults.


All this worked well in the original WatchKit. I know, because I used it.


With Watch OS 2, the WatchKit extension runs on the watch and not on the phone. App Groups are [apparently] no longer used. At least, I have tried using them and the settings do not transfer from the iPhone to the watch.


So: in Watch OS 2, how and where are the settings specified by the WatchKit settings bundle stored, and how can they be retrieved by the extension running on the watch?

Replies

This is all code needed to access Settings-Watch.bundle in watchOS 2:

    NSUserDefaults *sharedDefaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.com.mycompany.myapp"];

    // get stored settings
    self.soundsEnabled = [[sharedDefaults objectForKey:@"enabled_sounds"] boolValue];
    self.hapticEnabled = [[sharedDefaults objectForKey:@"enabled_haptic"] boolValue];

    [sharedDefaults release];

As you can see, there is no WCSession objects.

It works good on watchOS 2 GM on a real device.

In old betas it didn't work.

Does it work in the simulator? Because that is all that I have access to at the moment.

Are you sure you build the app as WatchOS 2 app?

Yes, I'm sure.

You have App Groups enabled with the right identifier in your watch extension and iOS app, correct?

Right. App groups is enabled for both the watch extension and the iOS app and even for the watch app itself.

I GOT IT WORK. I can't believe nobody that has this working noticed the solution. Are you ready? You need to enable App Groups for the iOS app, watch extension, and watch app. That's right, even though there is no mention of this new requirement to add the App Groups ability to the watch app target in the docs, you need to do it! And there is another thing, it only works in real device and not in simulator!


Will be updating my bug report at Apple with this discovery. Hopefully someone will bother mentioning this in the docs. Thank you to me!

You definitly save me tons of hours of desperation. :-) The hint about it working on a real device only was the point. Unfortunately I don't own a apple watch yet. :-/


Dirk