Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Write into a database stored in App Group container from extension

I have a sqlite database stored in the App Group container in order to register custom shortcut.

I can read/write into it from the app, but not from the keyboard extension. It seems that the database is in read-only mode from extensions.

I'm using the following code to access it:

let appGroupDirectoryPath = NSFileManager.defaultManager().containerURLForSecurityApplicationGroupIdentifier(appGroupId)
let dataBaseURL = appGroupDirectoryPath!.URLByAppendingPathComponent("database.sqlite")

Is there a workaround to be able to write into the database from the extension keyboard, or is it completely impossible?

The database is writable from the simulator but not with real devices. I guess it's because permissions are managed differently on MacOS X and iOS.

like image 331
Matthew Avatar asked May 02 '15 15:05

Matthew


1 Answers

Figured it out.

For keyboards, there is a property in the Info.plist file called RequestsOpenAccess. You can turn this on to enable write access to the shared container.

However, the end user will have to turn on "full access" in their settings for this keyboard, and they will be prompted with a scary message about how you could be logging their keystrokes.

Here's the Apple article that explains it:

Designing for User Trust for Custom Keyboard

like image 78
Chase Finch Avatar answered Sep 19 '22 05:09

Chase Finch