Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios8 iOS 8应用程序扩展从safari获取图像_Ios8_Sharing - Fatal编程技术网

Ios8 iOS 8应用程序扩展从safari获取图像

Ios8 iOS 8应用程序扩展从safari获取图像,ios8,sharing,Ios8,Sharing,我正在我的应用程序上使用应用程序扩展共享 把分享的url和“消息”还给我,效果很好, 但我的图像在登录时显示为零 @interface ShareViewController () @property (nonatomic, strong)__block NSString *urlString; @property (nonatomic, strong)__block UIImage *photo; @property (nonatomic, strong)NSString *msg; @end

我正在我的应用程序上使用应用程序扩展共享

把分享的url和“消息”还给我,效果很好, 但我的图像在登录时显示为零

@interface ShareViewController ()
@property (nonatomic, strong)__block NSString *urlString;
@property (nonatomic, strong)__block UIImage *photo;
@property (nonatomic, strong)NSString *msg;
@end

@implementation ShareViewController

- (BOOL)isContentValid {
    // Do validation of contentText and/or NSExtensionContext attachments here
    return YES;
}

- (void)viewDidLoad{

    [super viewDidLoad];

    //Get msg
    NSExtensionContext *myExtensionContext = [self extensionContext];
    NSArray *inputItems = [myExtensionContext inputItems];
    for(NSExtensionItem* item in inputItems){
        self.msg = [NSString stringWithFormat:@"%@", [item.attributedContentText string]];
    }

    // get url
    NSExtensionItem *item = self.extensionContext.inputItems.firstObject;
    NSItemProvider *itemProvider = item.attachments.firstObject;

    if ([itemProvider hasItemConformingToTypeIdentifier:(NSString *)kUTTypeURL]) {
        [itemProvider loadItemForTypeIdentifier:(NSString *)kUTTypeURL options:nil completionHandler:^(NSURL *url, NSError *error) {
            self.urlString = [NSString stringWithFormat:@"%@",url.absoluteString];
        }];
    }


    //img
    if ([itemProvider hasItemConformingToTypeIdentifier:(NSString *)kUTTypeImage]) {
        [itemProvider loadItemForTypeIdentifier:(NSString *)kUTTypeImage options:nil completionHandler:^(UIImage *image, NSError *error) {
            self.photo = image;
        }];
    }

}

- (void)didSelectPost {
    // This is called after the user selects Post. Do the upload of contentText and/or NSExtensionContext attachments.

    NSLog(@"big fat fella");
    NSLog(@"msg: %@", self.msg);
    NSLog(@"url %@:", self.urlString);
    NSLog(@"im %@:", self.photo);

    // Inform the host that we're done, so it un-blocks its UI. Note: Alternatively you could call super's -didSelectPost, which will similarly complete the extension context.
    [self.extensionContext completeRequestReturningItems:@[] completionHandler:nil];
}
所以请注意,我在didSelectPost上获得了url和消息,但图像显示为空

如何获得图像?
谢谢

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

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

NSString * const NSItemProviderPreferredImageSizeKey;

参考:

对于从Safari共享的图像,图像始终为零
NSString * const NSItemProviderPreferredImageSizeKey;