My app has the following targets:
- iOS App
- Today Extension
- Apple Watch App
- Apple Watch Extension
All of these targets have the "App Group" capability with the correct group selected. In the main iOS app, I synchronize the settings like so:
NSUserDefaults * sharedDefaults = [[NSUserDefaults alloc]initWithSuiteName:@"group.foo.bar"];
if([sharedDefaults respondsToSelector:@selector(setObject:forKey:)]){
// Example Value
[sharedDefaults setObject:@"TestString" forKey:@"TestString"];
[sharedDefaults synchronize];
}
The Today Extension uses the following to get the settings, which works just fine:
NSUserDefaults * defaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.foo.bar"];
NSLog(@"String: %@", [defaults stringForKey:@"TestString"]);
// String: TestString
The watch extension uses the same line of code to get the settings as the today extension, however it does not work. In the console I see String: (null)
. What am I doing incorrectly?