[英]Shared file between app extension and main app
I need your help to figure out how to make my .json file accessible by both the main app and the app extension. 我需要您的帮助,以确定如何使主应用程序和应用程序扩展程序都可以访问我的.json文件。 I have an extension that, when the post button is pressed, writes some data in a .json file.
我有一个扩展名,当按下发布按钮时,它会将一些数据写入.json文件中。 But when I try to read the file in the main app, the main app reads a blank file in a wrong path, in fact the app reads in this position: https://i.stack.imgur.com/idP3d.png and the extension writes a file in this path: https://i.stack.imgur.com/v8yhr.png .
但是,当我尝试在主应用程序中读取文件时,主应用程序以错误的路径读取了空白文件,实际上,该应用程序的读取位置为: https : //i.stack.imgur.com/idP3d.png和扩展名将在以下路径中写入文件: https : //i.stack.imgur.com/v8yhr.png 。 I have tried to include the file in the bundle resources and set the membership of the file for both the apps, but nothing worked.
我试图将文件包含在捆绑资源中,并为两个应用程序设置文件的成员身份,但是没有任何效果。 To get the path of the files I use this method:
要获取文件的路径,请使用以下方法:
let file = Bundle.main.url(forResource: "commonfile", withExtension: "json")
You help is really appreciated 非常感谢您的帮助
You can use App Group feature to share file between apps/extensions: 您可以使用“应用程序组”功能在应用程序/扩展名之间共享文件:
appGroupURL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "YOUR_GROUP_BUNDLE_ID")
appGroupURL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "YOUR_GROUP_BUNDLE_ID")
Hope this helps. 希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.