1

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

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.

Or should I place this main.jsbundle in an app group so both app and extension can use it?

clemens
  • 16,716
  • 11
  • 50
  • 65
manuelBetancurt
  • 15,428
  • 33
  • 118
  • 216

1 Answers1

1

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.

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. 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.

clemens
  • 16,716
  • 11
  • 50
  • 65
  • hi, @clemens as the only file I need to share is the JS bundle can I just copy/paste the JS file on both my main project and the extension? thanks – manuelBetancurt Mar 05 '18 at 03:44
  • @MaKo: This is very easy to achieve. Open the file inspector for the JS bundle and select the targets to which you want to copy the bundle. – clemens Mar 05 '18 at 05:21