自定義UIActivity類永部,實(shí)現(xiàn)一下方法:
- (NSString *)activityType { return @"customAppType"; }
- (NSString *)activityTitle { return self._activityTitle;}
- (UIImage *) activityImage { return self._activityImage; }
- (BOOL) canPerformWithActivityItems:(NSArray *)activityItems { return YES; }
- (void) prepareWithActivityItems:(NSArray *)activityItems { }
- (UIViewController *) activityViewController { return nil; }
- (void) performActivity {
[[UIApplication sharedApplication] openURL:self._activityUrl];
}
//使用
CustomAcitivity *activity = [[CustomAcitivity alloc] initWithTitie:@"Hello" withActivityImage:[UIImage imageNamed:@"5.png"] withUrl:[NSURL URLWithString:@"http://www.baidu.com"]];
NSArray *applicationActivities = [[NSArray alloc] initWithObjects:activity, nil];
UIActivityViewController *activityVC =
[[UIActivityViewController alloc] initWithActivityItems:activityItems
applicationActivities:applicationActivities];
activityVC.excludedActivityTypes = @[UIActivityTypePostToWeibo, UIActivityTypeAssignToContact, UIActivityTypePrint ,UIActivityTypeCopyToPasteboard,UIActivityTypeAssignToContact,UIActivityTypeSaveToCameraRoll,UIActivityTypeMessage ];
[self presentViewController:activityVC animated:YES completion:nil];