0

i was used app group to share data with my apple watch and today extension from my app. the problem is i can able to get that app group data in today extension but i can't able to get this data in apple watch. so i just want to make sure that can i used the app group to access it in today extension and even apple watch and which is the best way to share data with apple watch?

i used this to share data to app group

NSUserDefaults *sharedDefaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.com.myapp.data"];
    [sharedDefaults setObject:[[NSUserDefaults standardUserDefaults]objectForKey:@"array1"] forKey:@"arrayVisibleCountryList"];
    [sharedDefaults setObject:[[NSUserDefaults standardUserDefaults]objectForKey:@"array2"] forKey:@"arrayBaseCurrency"];
    [sharedDefaults synchronize];

to retrive data from app group

NSUserDefaults *sharedDefaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.com.myapp.data"];
    NSMutableArray *array1=[[sharedDefaults objectForKey:@"array1"]mutableCopy];
    NSMutableArray *array2=[[sharedDefaults objectForKey:@"array2"]mutableCopy];
PinkeshGjr
  • 8,460
  • 5
  • 41
  • 56

1 Answers1

1

This would have only worked in watchOS 1, when the watch extension ran on the phone, and could have accessed the phone's app group container.

In watchOS 2 or later, it's not possible to use an app group to share data between the phone and watch. You need to use Watch Connectivity to transfer data between the phone and the watch.

  • i was used watch connectivity too but the problem with it is if i don't open my actual app then i cant able to get data sync to my apple watch – PinkeshGjr Jul 02 '16 at 04:28
  • It is possible to use `sendMessage` to launch the iOS app in the background, and it can then reply to the watch with the requested data. –  Jul 02 '16 at 04:30
  • thanks bro let me try this, this would be really help me solve my problem – PinkeshGjr Jul 02 '16 at 04:33