使用UIDocumentInteractionController和UIActivityViewController时禁用共享扩展选项

时间:2016-12-06 04:57:28

标签: ios uiactivityviewcontroller uidocumentinteraction ios8-share-extension

我习惯使用UIDocumentInteractionControllerUIActivityViewController与特殊UTI分享数据。

但是,当其他应用使用Share Extension时,共享界面弹出窗口可能会有选项,例如copy tp xxximport to xxx

如何禁用这些选项,或者是否有任何其他方式可以将数据共享到我可以控制的指定应用程序。

// ======= 我的代码是这样的:

UIActivityViewController *activity = [[UIActivityViewController alloc] initWithActivityItems:@[itemUrl] applicationActivities:nil];
activity.excludedActivityTypes = @[UIActivityTypePostToFacebook, UIActivityTypePostToFacebook,UIActivityTypePostToWeibo,
                                   UIActivityTypeMessage, UIActivityTypeMail, UIActivityTypePrint, UIActivityTypeCopyToPasteboard,
                                   UIActivityTypeAssignToContact, UIActivityTypeSaveToCameraRoll, UIActivityTypeAddToReadingList,
                                   UIActivityTypePostToFlickr, UIActivityTypePostToFlickr, UIActivityTypePostToFlickr,
                                   UIActivityTypeAirDrop];
[self presentViewController:activity animated:YES completion:NULL];

2 个答案:

答案 0 :(得分:0)

创建一个数组并添加不想向用户显示的类型,例如

NSArray *excludeActivities = @[UIActivityTypeAirDrop,
                                       UIActivityTypePrint,
                                       UIActivityTypeAssignToContact,
                                       UIActivityTypeSaveToCameraRoll,
                                       UIActivityTypeAddToReadingList,
                                       UIActivityTypePostToFlickr,
                                       UIActivityTypePostToVimeo,
                                       UIActivityTypeCopyToPasteboard];

Create a instance of UIActivityViewController
And set following propery
activityViewController.excludedActivityTypes = excludeActivities

答案 1 :(得分:0)

我发现如果您分享为NSURL,您将获得copy to xxximport to xxx,但如果您分享为UIImage,则无法获得该信息。

将显示import to xxx

avc = [[UIActivityViewController alloc] initWithActivityItems:[NSArray arrayWithObjects:fileURL, nil] applicationActivities:nil];
[self presentViewController:avc animated:YES completion:nil];

不会显示

UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:fileURL]];
avc = [[UIActivityViewController alloc] initWithActivityItems:[NSArray arrayWithObjects:image, nil] applicationActivities:nil];
[self presentViewController:avc animated:YES completion:nil];