IOS 8 Share Safari Image Extension

I installed the extension for sharing in my iOS 8 application and everything is working fine. I can share with photo app or with Safari. But when I'm in Safari, I have no idea how to get the generated thumbnail image of the web page. I registered the correct NSExtensionActivationRule. When I share a photo from the Photos application, the NSItemProvider object type says it is public.jpeg and I can use

[itemProvider loadItemForTypeIdentifier:(NSString *)kUTTypeImage options:nil completionHandler:^(UIImage *image, NSError *error) { [self.extensionContext completeRequestReturningItems:@[] completionHandler:nil]; }]; 

to get an image

But when I share with Safari, the NSItemProvider type says it's public.url and I have no idea how to get the image? I know how to get the url by running loadItemForTypeIdentifier: @ "public.url", but how do I get the image?

+5
source share
2 answers

In the sharing extension, you can configure the javascript preprocessor to access the web page and return information such as a preview image.

Details for configuring the js preprocessor are given here: https://developer.apple.com/library/prerelease/ios/documentation/General/Conceptual/ExtensibilityPG/ExtensionScenarios.html#//apple_ref/doc/uid/TP40014214-CH21-SW12

0
source

I can get the generated thumbnail when sharing a web page, although I can not change its size.

To get an image automatically created in the share extension when shared in Safari, use loadPreviewImageWithOptions: completeHandler: previewImageHandler.

 [itemProvider loadPreviewImageWithOptions:nil completionHandler:^(UIImage *image, NSError *error){ if(image){ //do anything here with the image } } 

I can get the sketch automatically generated when shared in Safari, but I can not resize the image using:

 NSString * const NSItemProviderPreferredImageSizeKey; 

Link: https://developer.apple.com/library/ios/documentation/Foundation/Reference/NSItemProvider_Class/

Check and see if this helps you.

-1
source

All Articles