[英]iOS share extension URLForResource access file in main app
I need to access a file from my main app in my share extension is that possible?我需要从我的共享扩展中的主应用程序访问文件,这可能吗? The file is the "bundle" for distribution for a react native iOS app, something like该文件是用于分发本机 iOS 应用程序的“捆绑包”,例如
jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle" subdirectory:@"../myMainProject"];
If I copy and paste the main.jsbundle
file on my share extension it works fine.如果我将main.jsbundle
文件复制并粘贴到我的共享扩展上,它可以正常工作。
Or should I place this main.jsbundle
in an app group so both app and extension can use it?或者我应该将此main.jsbundle
放在应用程序组中,以便应用程序和扩展程序都可以使用它?
An app and its extensions can only share data over a common app group folder, and both must be added explicitly in Xcode to that group.应用程序及其扩展程序只能通过通用应用程序组文件夹共享数据,并且两者都必须在 Xcode 中明确添加到该组。
If your JavaScript bundle is static and is delivered with your app, you max place it as a resource into a shared framework, and add this framework to both app and extension.如果您的 JavaScript 包是静态的并且与您的应用程序一起交付,您最多可以将它作为资源放入共享框架中,并将此框架添加到应用程序和扩展程序中。 So you can access this bundle by所以你可以通过以下方式访问这个包
jsCodeLocation = [[NSBundle bundleWithIdentifier: <framework identifier>] URLForResource:@"main" withExtension:@"jsbundle"];
Note : You shouldn't access the contents of the parent folder of a bundle folder.注意:您不应访问捆绑文件夹的父文件夹的内容。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.