Reputation: 47
since days I try to get some data vom the parent to my WatchKitApp. I added a group to the parent, to WatchApp and WatchApp Extension. Then I use this code to save the data in Objective-C:
NSUserDefaults *defaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.mygroup"];
[defaults setInteger:5 forKey:@"test"];
[defaults synchronize];
Then I try to get the data from the WatchKit in Swift:
let defaults = NSUserDefaults(suiteName: "group.mygroup")
let integer = defaults!.integerForKey("test")
print("Test \(integer)")
In my opinion the code and setting are right. I don't know what I'am doing wrong.
Upvotes: 0
Views: 592
Reputation: 47
If you are using watchOS 2.0, shared groups are no longer supported, you must use Watch Connectivity framework instead. See my answer to a similar question here: stackoverflow.com/questions/30851729/… I would recommend switching now as the OS will be out in the fall. – rmp 15 hours ago
Yes this was my Problem thx :)
Upvotes: 1
Reputation: 8942
Make sure your suite name fits the group name you have already set up for your group. To look up your group name, go to the project editor, select your app as the target and go to capabilities. Expand the app group cell and look up the name there.
1:
2:
Upvotes: 1