Reputation: 81
I managed to read data in a Today Extensions from the companion app with code like
NSUserDefaults *defaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.cdm.TodayExtensionSharingDefaults"];
NSData *encodedObject = [defaults objectForKey:@"DataContactList"];
CV_DataContactList *object = [NSKeyedUnarchiver unarchiveObjectWithData:encodedObject];
with the corresponding writing code in the companion app
NSUserDefaults *defaults = [[NSUserDefaults alloc] initWithSuiteName:@"group.cdm.TodayExtensionSharingDefaults"];
NSData *encodedObject = [NSKeyedArchiver archivedDataWithRootObject:self];
[defaults setObject:encodedObject forKey:@"DataContactList"];
[defaults synchronize];
I created the app group and added in the Capabilities of both target (extension and companion app). All is working fine in the simulator and data are passed as soon as the companion app changes them.
But when I run the extension on the device it cannot read any data. I got the
<Warning>: *** -[NSKeyedUnarchiver initForReadingWithData:]: data is NULL
on the console log.
I tried to also generate provisioning profiles, with right appid and app group, from scratch but it didn't solve.
I appreciate any help. Thanks!
Upvotes: 2
Views: 308
Reputation: 105
Try adding the class file where you save your data in TodayExtension target > Build Phases > Compile Sources. You have add only the .m files in it. For example: If the data saved file is MyData.m check if that file is presented in Target of your project and today extn target.
If this doesn't work and any of you have already found the solution please add it so it will be helpful later.
Upvotes: 0