0

I am trying to share common data between my iPhone app and its extension app on Apple watch. Like the following:

//set
NSUserDefaults *groupDefaults = [[NSUserDefaults alloc]   initWithSuiteName:@"group.com.appName"];
[groupDefaults setObject:someArray forKey:@"someArrayKey"];
[groupDefaults synchronize];

//get
NSUserDefaults *groupDefaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.com.appName"];
NSArray *someArray = [groupDefaults objectForKey:@"someArrayKey"];

I also turn on App Groups both for the iPhone and Apple Watch apps. I have also modified the app id to support this and generated a new provisioning profile.

But the content of someArray , is different when running on the Watch and on the Phone.

Like on the Watch I see only the data I store from the watch, and the same on the Phone.

what is missing here?

shebelaw
  • 3,992
  • 6
  • 35
  • 48
  • 1
    If you're using watchOS 2 then the watch doesn't share app groups with the phone. – dan Oct 19 '15 at 22:11
  • yes, I am using watchOS2, are you sure? I have seen some samples on how to communicate watch and phone in real time while both apps are active on both devices. but that is not what I am looking for. so what is the solution for this situation? – shebelaw Oct 20 '15 at 01:19
  • You can use the `WCSession` class in the WatchConnectivity framework to communicate between the parent app the and watch app. – dan Oct 20 '15 at 15:15
  • WCSession, I believe is when both apps on the two devices are active. – shebelaw Oct 21 '15 at 14:34
  • There's a few different methods on WCSession, some of which allow you to send data even when one app isn't active and it will receive it next time it launches and another which allows the watch app to cause the phone app to launch in the background and receive it immediately. – dan Oct 21 '15 at 15:07

0 Answers0