+ (void)shareWithTitle:(NSString *)title image:(UIImage *)image url:(NSString *)url target:(UIViewController *)target complete:(void (^)(BOOL isSuccess, UIActivityType type))complete
{
// 分享内容
NSString *shareTitle = title;
UIImage *shareImage = image;
NSURL *shareUrl = [NSURL URLWithString:url];
NSArray *activityItemsArray = @[shareTitle, shareImage, shareUrl];
//
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:activityItemsArray applicationActivities:nil];
activityVC.modalInPopover = YES;
// 禁用分享渠道
// activityVC.excludedActivityTypes = @[UIActivityTypePrint, UIActivityTypeCopyToPasteboard, UIActivityTypeAssignToContact, UIActivityTypeSaveToCameraRoll, UIActivityTypeAddToReadingList, UIActivityTypePostToFlickr, UIActivityTypePostToVimeo, UIActivityTypeAirDrop, UIActivityTypeOpenInIBooks];
//
activityVC.completionWithItemsHandler = ^(UIActivityType _Nullable activityType, BOOL completed, NSArray * _Nullable returnedItems, NSError * _Nullable activityError) {
if (complete) {
complete(completed, activityType);
}
};
//
[target presentViewController:activityVC animated:YES completion:nil];
}
网友评论