iOS 系统自带分享功能

2021-07-22  本文已影响0人  anny_4243
//分享的标题
NSString *textToShare = @"标题";
//分享的图片
UIImage *imageToShare = [UIImage imageNamed:@"logo.png"];
//分享的url
NSURL *urlToShare = [NSURL URLWithString:@"http://www.baidu.com"];

NSArray *activityItems = @[textToShare,imageToShare, urlToShare];
    
UIActivityViewController *activityVC = [[UIActivityViewController alloc]initWithActivityItems:activityItems applicationActivities:nil];

activityVC.excludedActivityTypes = @[UIActivityTypePrint, UIActivityTypeCopyToPasteboard,UIActivityTypeAssignToContact,UIActivityTypeSaveToCameraRoll];
    
[self presentViewController:activityVC animated:YES completion:nil];
    
//分享之后的回调
activityVC.completionWithItemsHandler = ^(UIActivityType  _Nullable activityType, BOOL completed, NSArray * _Nullable returnedItems, NSError * _Nullable activityError) {
    if (completed) {
        NSLog(@"completed");
        //分享 成功
    } else  {
        NSLog(@"cancled");
        //分享 取消
    }
};
上一篇下一篇

猜你喜欢

热点阅读