iOS8 custom keyboard accessing user defaults witho

2019-05-30 08:59发布

问题:

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.

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?

回答1:

There is no way to share content between host app and keyboard extension without requestOpenAccess.

You have to enabled a shared container for host app and keyboard extension, and use

[[NSUserDefaults alloc] initWithSuiteName:];

to access a shared NSUserDefaults.

Yes it is overkill, but this is the only way.