3

I am building a custom keyboard that learns the way you type for smarter auto-correct. In order to learn...

I need to be able to STORE data to the users device. I've tried using NSFileManager with NSDocumentsDirectory but nothing is getting saved int he AppExtension. (I tested the code (copy paste) in a regular app (non-app-extension) and it worked). I even enabled "Requests Open Access" in the .plist and re-installed the keyboard... still wouldn't save data.

Is there a way to store data in an app-extension?


Possible solutions I've pondered:

•Maybe creating a contact in the users address book that has my info in it (if app-extensions are allowed to do that), but a user might be suspicious as to why my app is requesting permission to modify their contact's address book).

•Displaying a hidden UIWebView that uses javascript injection to store and read data Safari Javascript Database, but I'm afraid this data might be erased if cache is ever cleared.

4

1 回答 1

0

编辑:现在这在 iDevice beta 5 上不再适用于我(启用或禁用 requestOpenAccess)?但它仍然适用于 SIMULATOR beta 5?嗯

__下面的原始帖子:_

事实证明 NSUserDefaults 确实保存了数据,它只是在 BETA 3 模拟器上不起作用,但在 BETA 5 iDevice 上确实有效。RequestsOpenAccess 不需要启用!

NSUserDefaults *defaults = [[NSUserDefaults alloc]initWithSuiteName:@"com.company.keyboard.uniqueCodeHere"];//uniqueCodeHere can be anything... we just have to make sure the SuiteName isn't equal to your info.plist bundle ID so we add a random uniqueCode to the end of this ID.
[defaults setObject:@"myStringData" forKey:@"savedStrings"];
[defaults synchronize];

*注意,SuiteName 不能等于 info.plist 中的包 ID,否则由于某种原因它不起作用...

于 2014-08-16T19:34:51.993 回答