I'm using iOS 6 new way to share information : UIActivityViewController
. To select the shared data depending on the media (facebook, twitter or mail) my view controller implement the UIActivityItemSource
Protocol as follow :
- (IBAction)onShareButton:(UIButton *)sender
{
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:@[self] applicationActivities:nil];
activityViewController.excludedActivityTypes = @[UIActivityTypeMessage, UIActivityTypeAssignToContact, UIActivityTypeCopyToPasteboard, UIActivityTypeMessage, UIActivityTypePostToWeibo, UIActivityTypePrint, UIActivityTypeSaveToCameraRoll];
[self presentViewController:activityViewController animated:YES completion:^{}];
}
#pragma mark - UIActivityItemSource Protocol
- (id)activityViewController:(UIActivityViewController *)activityViewController itemForActivityType:(NSString *)activityType {
if ([activityType isEqualToString:UIActivityTypePostToFacebook]) {
NSArray *items = @[@"message facebook", [NSURL URLWithString:@"http://www.myUrlFacebook.com"]];
return items;
} else if ([activityType isEqualToString:UIActivityTypePostToTwitter]) {
NSArray *items = @[@"message twitter", [NSURL URLWithString:@"http://www.myUrlTwitter.com"]];
return items;
} else if ([activityType isEqualToString:UIActivityTypeMail]) {
NSArray *items = @[@"message mail", [NSURL URLWithString:@"http://www.myUrlMail.com"]];
return items;
}
NSArray *items = @[@"Not a proper Activity", [NSURL URLWithString:@"http://www.myUrlMail.com"]];
return items;
}
- (id)activityViewControllerPlaceholderItem:(UIActivityViewController *)activityViewController {
return @"PlaceHolder";
}
When I'm returning a simple NSString for activityViewController:itemForActivityType:
the string is well used by my UIActivityViewController
, but I can't find a way to use an Array
!
According to Apple Documentation it should be possible :
This method returns the actual data object to be acted on by an activity object Apple documentation
Does anyone ever use this UIActivityItemSource
Protocol with Arrays, or is there a use full tutorial to do that ?
Note : I also got this error on the console, it may help ...
Launch Services: Registering unknown app identifier com.apple.mobilemail failed
Launch Services: Unable to find app identifier com.apple.mobilemail
After spending a significant amount of time trying to figure this one out, it seems it isn't possible to pass it an NSArray
of items. So I extended UIActivityViewController
to make it possible.