简体   繁体   English

从扩展名写入存储在App Group容器中的数据库

[英]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文章:

Designing for User Trust for Custom Keyboard 设计自定义键盘的用户信任

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法从iOS 10中的App组共享容器中获取扩展程序中的图像 - Not able to fetch images in extension app from App group shared container in iOS 10 图像不会从应用程序存储到数据库 - Image is not stored from app to database 从XCode下载共享的应用程序组容器 - Download shared App Group Container from XCode 如何在扩展程序和容器应用程序之间共享SQLite数据库 - How to share a SQLite database between an extension and the container app 将现有 Realm 数据库文件复制到 App Group 位置以进行今天的扩展 - Copy existing Realm database file to App Group location for today extension 无论如何,可以通过iOS 8.3中的应用扩展打开容器应用吗? - Is there anyway of opening the container app from an app extension in iOS 8.3? 如何创建/使用共享应用程序组容器作为包含应用程序及其在ios中的扩展名之间的缓存存储 - How to create/use a shared app group container as cache storage between containing app and it's extension in ios 有什么方法可以从容器应用程序中打开iMessage扩展? - Is there are way to open an iMessage extension from within the container app? 从容器应用程序和扩展程序访问核心数据 - Accessing Core Data from both container app and extension iOS - 广播上传扩展 - UserDidFinishSetup - 从容器应用传递参数 - iOS - Broadcast Upload Extension - UserDidFinishSetup - pass parameters from Container app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM