简体   繁体   English

主应用程序中的 iOS 共享扩展 URLForResource 访问文件

[英]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.

相关问题 主应用程序和共享扩展名之间的iOS共享.h文件 - iOS Sharing .h file between main app and share extension 从iOS Safari共享扩展打开主应用 - Open the main app from a iOS Safari Share Extension 用于在共享扩展和iOS应用之间共享文件路径/文件的代码 - Code to share file path/file between a share extension and iOS app 在 iOS 8 共享扩展和主应用程序之间共享数据 - Sharing data between an iOS 8 share extension and main app 如果用户安装了主应用程序,iOS共享扩展程序是否会自动安装? - Is that an iOS share extension will be installed automatically if user installed your main app? (iOS Swift)在应用程序和Today Extension之间共享EKEventStore和访问 - (iOS Swift) Share EKEventStore and access between app and Today Extension 如何与我的主应用程序和 iOS 应用程序的应用程序扩展正确共享 Amplify 框架? - How can I properly share the Amplify framework with my Main App and my App Extension for an iOS app? 向iOS应用添加共享扩展程序 - Add a share extension to an iOS app 如何在主iOS应用与其共享扩展之间使用相同的经过身份验证的用户令牌 - How to use same Authenticated user token between main iOS app and its Share Extension 是否可以从扩展名的主应用程序访问文件? - is it able to access the file from main app in it's extension?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM