I've been trying to use the new UIActivityViewController to replace all of my UIActionSheets for sharing, however I've run into an issue.
I have 5 activities, Message, Email, Copy, Twitter, and Facebook. I've already figured out how to have those show different text, through this in a custom UIActivityProvider subclass:
- (id) activityViewController:(UIActivityViewController *)activityViewController
itemForActivityType:(NSString *)activityType
{
if ( [activityType isEqualToString:UIActivityTypePostToTwitter] )
return twitter;
if ( [activityType isEqualToString:UIActivityTypePostToFacebook] )
return facebook;
if ( [activityType isEqualToString:UIActivityTypeMessage] )
return urlScheme;
if ( [activityType isEqualToString:UIActivityTypeMail] )
return urlScheme;
if ( [activityType isEqualToString:UIActivityTypeCopyToPasteboard])
return urlScheme;
return nil;
}
And this in my view controller:
ActivityProvider *aProvider = [[ActivityProvider alloc] init];
aProvider.facebook = facebook;
aProvider.twitter = twitter;
aProvider.urlScheme = URL;
NSArray *Items = @[aProvider, sharedURL];
UIActivityViewController *activityVC = [[UIActivityViewController alloc]initWithActivityItems:Items applicationActivities:Nil];
activityVC.excludedActivityTypes = @[UIActivityTypePrint, UIActivityTypeAssignToContact,UIActivityTypeSaveToCameraRoll, UIActivityTypePostToWeibo];
[self presentViewController:activityVC animated:TRUE completion:nil];
However, I only want to show the URL (sharedURL) in the Facebook and Twitter share sheets, not the message, email or copy. Any way to accomplish this?
You should be able to do this implementing your own UIActivityItemProvider, and returning nil for any activity type where you don't want to use that data.
You can choose what to send to each type of activity. I created a custom activity provider and call it like this:
The custom provider is a subclass of UIActivityItemProvider
The guts of my custom provider class look something like this: