PinkeshGjr PinkeshGjr - 2 years ago 117
iOS Question

Can i used same app group in apple watch and today extension?

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. so i just want to make sure that can i used the same app group to access it in today extension and even apple watch and which is the best way to same data with apple watch?

i used this to share data to app group

NSUserDefaults *sharedDefaults = [[NSUserDefaults alloc] initWithSuiteName:@""];
[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:@""];
NSMutableArray *array1=[[sharedDefaults objectForKey:@"array1"]mutableCopy];
NSMutableArray *array2=[[sharedDefaults objectForKey:@"array2"]mutableCopy];

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download