美文网首页
iOS 系统自带分享功能

iOS 系统自带分享功能

作者: anny_4243 | 来源:发表于2021-07-22 15:36 被阅读0次
    //分享的标题
    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");
            //分享 取消
        }
    };
    

    相关文章

      网友评论

          本文标题:iOS 系统自带分享功能

          本文链接:https://www.haomeiwen.com/subject/kbzemltx.html