简体   繁体   English

iOS 8共享扩展Safari图像

[英]iOS 8 Share Extension Safari Image

I have set up a share extension in my iOS 8 app and everything is working fine. 我在iOS 8应用程序中设置了一个共享扩展程序,一切正常。 I can share from Photo app or from Safari. 我可以从Photo app或Safari分享。 But when I am in Safari, I have no idea how to get the generated thumbnail image of the web page. 但是当我在Safari中时,我不知道如何获取生成的网页缩略图。 I have registered the proper NSExtensionActivationRule's. 我已经注册了适当的NSExtensionActivationRule。 When I share a photo from the Photo app, the NSItemProvider object type says it is public.jpeg and I am able to use 当我从Photo应用程序共享照片时,NSItemProvider对象类型说它是public.jpeg并且我能够使用

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

in order to get the image 为了获得图像

But when I share from Safari, the NSItemProvider type says it is public.url, and I have no idea how to get the image? 但是当我从Safari共享时,NSItemProvider类型说它是public.url,我不知道如何获取图像? I know how to get the url, by doing loadItemForTypeIdentifier:@"public.url" but how do I get the image? 我知道如何获取url,通过执行loadItemForTypeIdentifier:@“public.url”但是如何获取图像?

Within the share extension, you can set up a javascript preprocessor to access the web page, and return information such as preview image. 在共享扩展中,您可以设置javascript预处理器来访问网页,并返回预览图像等信息。

Details for setting up the js preprocessor are here: https://developer.apple.com/library/prerelease/ios/documentation/General/Conceptual/ExtensibilityPG/ExtensionScenarios.html#//apple_ref/doc/uid/TP40014214-CH21-SW12 有关设置js预处理器的详细信息,请访问: https//developer.apple.com/library/prerelease/ios/documentation/General/Conceptual/ExtensibilityPG/ExtensionScenarios.html#//apple_ref/doc/uid/TP40014214-CH21- SW12

I'm able to get the generated thumbnail when sharing web page, though unable to modify the size of it. 我可以在共享网页时获取生成的缩略图,但无法修改它的大小。

To get the image automatically generated on the share extension while sharing on Safari, use loadPreviewImageWithOptions:completionHandler:previewImageHandler. 要在Safari上共享时在共享扩展上自动生成图像,请使用loadPreviewImageWithOptions:completionHandler:previewImageHandler。

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

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

}

I'm able to retrieve the thumbnail auto-generated while sharing on Safari, but I'm unable to change the size of the image using: 我可以在Safari上共享时检索自动生成的缩略图,但我无法使用以下方法更改图像的大小:

NSString * const NSItemProviderPreferredImageSizeKey;

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

Do check out and see if that helps you out. 请检查,看看是否有助于你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM