iOS8自定义键盘访问用户默认值而不请求开放访问 [英] iOS8 custom keyboard accessing user defaults without requesting open access
问题描述
我正在为iOS8实现自定义键盘。我有一个包含应用程序,将一些键盘特定值设置为 NSUserDefaults
,以便键盘可以从中读取。
I'm implementing a custom keyboard for iOS8. I have a containing app that sets a few keyboard specific values to NSUserDefaults
so that the keyboard can read from them.
这样可以正常工作,但我必须将 requestsOpenAccess
设置为yes以使其在设备上运行。
This works fine, however I must set requestsOpenAccess
to yes to get this working on device.
这对我来说似乎有些过分,我只想从包含应用程序中读取一些值。我不想要联网键盘的任何其他功能。
This seems like overkill to me, I only want to read a few values from the containing app. I don't want any of the other features of the networked keyboard.
是否有人知道是否有办法读取包含应用程序中设置的值而不请求打开访问?
Does any one know if there is a way to read values set in the containing app without requesting open access?
推荐答案
如果没有 requestOpenAccess,则无法在主机应用和键盘扩展之间共享内容
。
您必须为主机应用和键盘扩展启用共享容器,并使用
You have to enabled a shared container for host app and keyboard extension, and use
[[NSUserDefaults alloc] initWithSuiteName:];
[[NSUserDefaults alloc] initWithSuiteName:];
访问共享的NSUserDefaults。
to access a shared NSUserDefaults.
是的,它有点矫枉过正,但这是唯一的方法。
Yes it is overkill, but this is the only way.
这篇关于iOS8自定义键盘访问用户默认值而不请求开放访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!