iOS新手学习

iOS 使用系统分享功能

2023-01-30  本文已影响0人  阳光下的灰尘

系统分享功能 UIActivityViewController 简单使用

UIActivityViewController *activityVC = [[UIActivityViewController alloc]initWithActivityItems:@[@"图片UIImage",@"内容NSString",@"分享链接NSURL"] applicationActivities:nil];
    activityVC.definesPresentationContext = YES;
    //不出现在活动项目
    //activityVC.excludedActivityTypes = @[UIActivityTypePrint, UIActivityTypeCopyToPasteboard,UIActivityTypeAssignToContact,UIActivityTypeSaveToCameraRoll];
    [self presentViewController:activityVC animated:YES completion:nil];
    //分享之后的回调
    __weak typeof(activityVC) weekActivity = activityVC;
    activityVC.completionWithItemsHandler = ^(UIActivityType  _Nullable activityType, BOOL completed, NSArray * _Nullable returnedItems, NSError * _Nullable activityError) {
        
        if (completionBlock) {
            completionBlock(completed, activityError);
            
            [weekActivity dismissViewControllerAnimated:YES completion:nil];
        }
        
        if (completed) {
            NSLog(@"completed");
            //分享 成功
        } else {
            NSLog(@"失败");
            //分享 取消
        }
    };
上一篇 下一篇

猜你喜欢

热点阅读