3

I am developing a share extension for iOS 8 and it seem like i can run javascript code on page to grab some information like markup of the mage

But on the apple document it says that javascript code must be inside a .js file but my javascript code is coming from server and it is dynamic.

Is it possible to run javascript i downloaded from server or can I change js file contents everytime I need to use it?

Shashank Kulshrestha
  • 1,556
  • 17
  • 31

1 Answers1

1

You can't do this using the built-in support in the current share extension system.

The Javascript file needs to be listed by name in the extension's Info.plist, in the value of the NSExtensionJavaScriptPreprocessingFile key. The file named there needs to exist in the app extension's bundle. But bundles are not writeable, so you can't replace or change the file.

You might be able to do something like you describe if you:

  1. Include a basic JS file that just returns the entire page source to your extension.
  2. Use JavaScriptCore.framework to further process that data in your extension.

I don't know of any reason why that wouldn't work, but I haven't tried it, and it's kind of unusual. Still, given your needs, it's worth investigating.

Tom Harrington
  • 69,312
  • 10
  • 146
  • 170