Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Share extension with NSExtensionJavaScriptPreprocessingFile no image

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!

like image 695
Andres Avatar asked Feb 18 '16 01:02

Andres


1 Answers

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.

like image 113
Jannon Avatar answered Oct 18 '22 10:10

Jannon