简体   繁体   English

如何在扩展程序和容器应用程序之间共享SQLite数据库

[英]How to share a SQLite database between an extension and the container app

I want to share a SQLite database between an app extension and the container app. 我想在应用程序扩展和容器应用程序之间共享一个SQLite数据库。 The database is copied from the main bundle (of the container app) to an App Group. 数据库从(容器应用程序的)主捆绑包复制到应用程序组。 The extension reads and writes from that copy of the database. 该扩展名从该数据库副本读取和写入。 The problem is that if the extension is opened before the container app there is no database to read from. 问题在于,如果扩展在容器应用之前打开,则没有可读取的数据库。 What can I do? 我能做什么?

You could put a flag in NSUserDefaults based on the app group that indicates that the app has been opened once. 您可以根据应用程序组在NSUserDefaults中放置一个标志,指示该应用程序已被打开一次。 Then the extension can check for this "key" and if missing display an suitable message. 然后,扩展程序可以检查该“键”,如果丢失,则显示一条适当的消息。

How exactly are you copying the database to an App Group? 您如何精确地将数据库复制到应用程序组?

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM