8

I'm building an iOS Share extension. I need to grab some data from web pages so I'm using a JavaScript file to grab that data and send it back to the app to be used in the extension.

I noticed the following. When I set the NSExtensionJavaScriptPreprocessingFile key with my JavaScript file the SLComposeServiceViewController is showing up perfect but without image!

Like this:

enter image description here

If I remove the NSExtensionJavaScriptPreprocessingFile my SLComposeServiceViewController shows up like this:

enter image description here

But I need to access to some data from the Webpage (the one I grab with JS) but I also need that image! I'm completely lost how to get both or I don't even know if that's possible because Apple docs are kind of confusing.

Thanks!

Andres
  • 11,439
  • 12
  • 48
  • 87
  • 1
    Same struggle here. What did you end up finding out? – SAHM Sep 29 '17 at 20:58
  • 1
    After many hours of testing, I believe that you have to choose one or the other. You cannot have both the previewImage from the webpage, and use NSExtensionJavaScriptPreprocessingFile. Not the answer I had hoped to find. – SAHM Sep 30 '17 at 00:59

1 Answers1

2

I don't know the answer to this for sure, but I've been looking at questions about share extension myself and came across a couple that might be useful to you. The general idea is to continue using your JavaScript preprocessor and manually set the preview image.

Retrieve the image with something like:

[itemProvider loadPreviewImageWithOptions:nil completionHandler:^(UIImage *image, NSError *error){

   if(image){
        //do anything here with the image
   }

}

as described here: iOS 8 Share Extension Safari Image

And set the preview image of SLComposeServiceViewController by overriding loadPreviewView:

override func loadPreviewView() -> UIView! {        
  imagePreviewView = UIImageView(image: UIImage(named: "imageName"))
  return imagePreviewView
}

as described here: Change the preview image in an SLComposeServiceViewController

Again, I don't know if this will work. Just seems like it should from what I've read.

Community
  • 1
  • 1
Jannon
  • 113
  • 1
  • 7
  • 1
    No, I don't think this works. The same problem stated by the OP still stands. – SAHM Sep 30 '17 at 00:54
  • I tested this and it doesn't work. There is no image coming through - it makes me wonder if Apple has a default javascript processor that provides the image & when you add your own processor you overwrite theirs. – Trev14 Jan 10 '19 at 23:41