Sharing data with NSUserDefaults or Keychain

Is it possible to share data with a watchOS 2 app via NSUserDefaults or Keychain? The same code worked before, but I can't get anything to work on watchOS 2. Is Watch Connectivity my only option?

If you're talking about sharing data from your phone with a watchOS 2 app, than currently watch connectivity is your only option.


Dirk

The shared groups for sharing data via NSUserDefaults is no longer avalible since the Watch App Extention is now running on the watch itself. This applies to both watch apps developed for watchOS 1.0 and watchOS 2.0.


You'll need to use the watch connectivity framework to communicate between the watch and the iOS companion app. Unfrotauntely, it seems like many of the options in WatchConnectivity are not included in the first beta. So hang tight.

You can share data in the keychain between the iOS app and watchOS extension using the "Keychain Sharing" capability in the targets for both the iOS app and watchOS extension.


I haven't tried shaing NSUserDefaults but I can confirm the keychain sharing works.

(I do also have the "App Groups" cabability turned on too for all targets (iOS, watchOS app and watchOS extension) so I don't know if that matters!)


(iOS 9 b2 / watchOS b2)


(PS, if your Sam Soffes of SSKeychain fame I used SSKeychain to do the above! And thanks for the library too 🙂 )

Are you saying that shared KeyChains works with watchOS 2? I have been trying to get a definative answer on this (see post here: https://forums.developer.apple.com/thread/5938). Did you have to chainge anyting from watchOS 1? Any info would be greatly appreciated!

Yes, though after reading the post in your link I'll double check tomorrow just in case! (I know it doesn't work in the simulators).

There was never a watchOS 1 app, so I can't help you in that regard with changes sorry!


Cheers,


Rich

Thanks, please do let me know how your test goes....

Any luck with the keychain on a real device? Were you able to share it with the phone app?

Neither NSUserDefaults or the keychain are shared between iOS and watchOS. If you find it working in the simulator, that would be a bug. It definitely doesn't work on device.

Sharing data with NSUserDefaults or Keychain
 
 
Q