iOS 8 共享扩展 Safari 图像 [英] iOS 8 Share Extension Safari Image

查看:65
本文介绍了iOS 8 共享扩展 Safari 图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的 iOS 8 应用程序中设置了一个共享扩展,一切正常.我可以从照片应用程序或 Safari 共享.但是当我在 Safari 中时,我不知道如何获取生成的网页缩略图.我已经注册了正确的 NSExtensionActivationRule.当我从 Photo 应用程序共享照片时,NSItemProvider 对象类型说它是 public.jpeg,我可以使用

I have set up a share extension in my iOS 8 app and everything is working fine. I can share from Photo app or from Safari. But when I am in Safari, I have no idea how to get the generated thumbnail image of the web page. I have registered the proper NSExtensionActivationRule's. When I share a photo from the Photo app, the NSItemProvider object type says it is public.jpeg and I am able to use

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

为了得到图像

但是当我从 Safari 共享时,NSItemProvider 类型显示它是 public.url,我不知道如何获取图像?我知道如何通过执行 loadItemForTypeIdentifier:@"public.url" 获取 url,但如何获取图像?

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

推荐答案

我可以在分享网页时获得生成的缩略图,但无法修改其大小.

I'm able to get the generated thumbnail when sharing web page, though unable to modify the size of it.

要在 Safari 上共享时在共享扩展上自动生成图像,请使用 loadPreviewImageWithOptions:completionHandler:previewImageHandler.

To get the image automatically generated on the share extension while sharing on Safari, use loadPreviewImageWithOptions:completionHandler:previewImageHandler.

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

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

}

我可以检索在 Safari 上共享时自动生成的缩略图,但我无法使用以下方法更改图像的大小:

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:

NSString * const NSItemProviderPreferredImageSizeKey;

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

一定要检查一下,看看是否对您有帮助.

Do check out and see if that helps you out.

这篇关于iOS 8 共享扩展 Safari 图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆