[英]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. 我有一个存储在App Group容器中的sqlite数据库,以便注册自定义快捷方式。
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.
我想这是因为MacOS X和iOS上的权限管理方式不同。
Figured it out. 弄清楚了。
For keyboards, there is a property in the Info.plist
file called RequestsOpenAccess . 对于键盘,
Info.plist
文件中有一个名为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: 以下是解释它的Apple文章:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.