I am developing to-do list app. In this app, i add the today extension. It is used to show the to-do list for today.
This is the code for share data between app and today extension. For testing purpose i add the only one item in the NSUserDefaults.
App code for saving the data to NSUserDefaults.
NSUserDefaults *shared = [[NSUserDefaults alloc]initWithSuiteName:@"group.compname.appname"];
[shared setValue:@"Test" forKey:@"test"];
[shared synchronize];
Today extension code for fetch the data from NSUserDefaults
NSUserDefaults *shared = [[NSUserDefaults alloc]initWithSuiteName:@"group.compname.appname"];
NSString *str = [ shared valueForKey:@"test"] ;
NSLog(@" Text = %@", str);
I am always getting the 'null' value.
Sounds like you haven't added the group to the entitlements/capabilities.
From this site: http://www.shinobicontrols.com/blog/posts/2014/07/21/ios8-day-by-day-day-2-sharing-extension