[英]Can't share data between app and today extension
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. 这是用于在应用程序和Today Extension之间共享数据的代码。 For testing purpose i add the only one item in the NSUserDefaults.
为了进行测试,我在NSUserDefaults中添加了唯一一项。
App code for saving the data to NSUserDefaults. 用于将数据保存到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中获取数据
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 从此网站上: http : //www.shinobicontrols.com/blog/posts/2014/07/21/ios8-day-by-day-day-2-sharing-extension
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.