希望这可以帮助某人。如果您将其子类化,这非常简单UIActivityItemProvider
:
@interface MyActivityItemProvider : UIActivityItemProvider
@end
@implementation MyActivityItemProvider
- (id)item
{
// Return nil, if you don't want this provider to apply
// to a particular activity type (say, if you provide
// print data as a separate item for UIActivityViewController).
if ([self.activityType isEqualToString:UIActivityTypePrint])
return nil;
// The data you passed while initialising your provider
// is in placeholderItem now.
if ([self.activityType isEqualToString:UIActivityTypeMail] ||
[self.activityType isEqualToString:UIActivityTypeCopyToPasteboard])
{
return self.placeholderItem;
}
// Return something else for other activities. Obviously,
// you can as well reuse the data in placeholderItem here.
return @"Something else";
}
@end
然后将其带有活动项数组的实例传递给 UIActivityViewController:
MyActivityItemProvider *activityItem =
[[MyActivityItemProvider alloc] initWithPlaceholderItem:@"Your data"];
NSArray *sharingItems = [NSArray arrayWithObjects:
activityItem, _myUITextView.viewPrintFormatter, nil];
UIActivityViewController *activityController =
[[UIActivityViewController alloc]
initWithActivityItems:sharingItems applicationActivities:nil];