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:
If I remove the NSExtensionJavaScriptPreprocessingFile
my SLComposeServiceViewController
shows up like this:
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!
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With