简体   繁体   English

ios8扩展和容器应用程序如何共享数据

[英]ios8 extension and container app how to share data

I'm having trouble to share data between iOS 8 extension and container app. 我无法在iOS 8扩展程序和容器应用程序之间共享数据。 I set up the group from develop portal and Xcode, and my entitlements plist both look like: 我从开发门户网站和Xcode设置了这个组,我的权利包括:

<dict>
    <key>com.apple.security.application-groups</key>
    <array>
        <string>my group id</string>
    </array>
</dict>

The suggested solution in apple document to use [[NSUserDefaults standardUserDefaults] 苹果文档中建议使用的解决方案[[NSUserDefaults standardUserDefaults]

doesn't work for me. 不适合我。

I've tried the solution by @Santa Claus from this post Communicating and persisting data between apps with App Groups to use 我已经尝试过@Santa Claus在这篇文章中使用App Group进行通信和持久化数据的解决方案

[[NSUserDefaults alloc] initWithSuiteName:@"<group identifier>"];

Santa Claus's solution worked on simulator but not on my iPhone 4s, any ideas on how to make it work on real device? 圣诞老人的解决方案适用于模拟器但不适用于我的iPhone 4s,有关如何使其在真实设备上运行的任何想法? Or am I missing anything? 或者我错过了什么?

Some updates: 一些更新:

[[NSFileManager defaultManager] containerURLForSecurityApplicationGroupIdentifier:@"group id"];

function returns url, and both urls from container app and extension look the same, as " path /private/var/mobile/Containers/Shared/AppGroup/3DFB9750-A9F3-4C37-BC3C-0D5BF746B‌​233" . 函数返回url,来自容器app和扩展名的两个url看起来都相同,如“ path / private / var / mobile / Containers / Shared / AppGroup / 3DFB9750-A9F3-4C37-BC3C-0D5BF746B 233” I created a json file inside that folder from container app but extension can't find any file in the folder when I run on device. 我在容器应用程序中的该文件夹中创建了一个json文件,但是当我在设备上运行时,扩展程序无法在文件夹中找到任何文件。 But in simulator it finds it well and everything works. 但在模拟器中,它找到了很好,一切正常。

My solution is edit the Info.plist of my custom keyboard: 我的解决方案是编辑我的自定义键盘的Info.plist:

NSExtension -> NSExtensionAttributes -> RequestsOpenAccess NSExtension - > NSExtensionAttributes - > RequestsOpenAccess

Make it YES. 是的。

Then delete the keyboard in your device and re-add it. 然后删除设备中的键盘并重新添加。 In your keyboard add page you will find a setting named "Allow Full Access", enable it and the keyboard will access the shared data. 在键盘添加页面中,您将找到名为“允许完全访问”的设置,启用它,键盘将访问共享数据。

For keyboard extension, make sure enable RequestsOpenAccess as heheBear's answer 对于键盘扩展,请确保启用RequestsOpenAccess作为heheBear的答案
and try remove and add back keyboard from Setting/Keyoboard occasionally 并尝试偶尔从Setting / Keyoboard中删除并添加键盘
keyboard extension is not stable and performance is really bad since beta 4, include beta 5 键盘扩展程序不稳定,自beta 4以来性能非常差,包括beta 5

问题只发生在自定义键盘上,iOS8 beta 2解决了这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM