美文网首页
iOS系统原生分享-UIActivityViewControll

iOS系统原生分享-UIActivityViewControll

作者: 智狸 | 来源:发表于2019-06-03 17:02 被阅读0次

+ (void)shareShowInViewController:(UIViewController*)viewController {

    // 分享的title

    NSString*textToShare =@"我是ZL,欢迎关注我!";

    // 分享的图片

    UIImage*imageToShare = [UIImageimageNamed:@"icon-60"];

    // 分享的链接地址

    NSURL *urlToShare = [NSURL URLWithString:@"https://www.jianshu.com/u/9cb1a1857948"];

    // 顺序可以混乱,系统会自动识别类型

    NSArray*activityItems =@[textToShare,urlToShare,imageToShare];

    // 调起系统分享视图

    UIActivityViewController *vc = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:@[]];

    // 设置忽略分享App的属性

    //    vc.excludedActivityTypes = @[UIActivityTypePostToVimeo];

    // 分享结果后的回调Block

    vc.completionWithItemsHandler= ^(UIActivityType  _NullableactivityType,BOOLcompleted,NSArray*_NullablereturnedItems,NSError*_NullableactivityError) {

        NSLog(@"%@", activityType);

        if(completed) {

            [[[UIAlertView alloc] initWithTitle:@"shared successful." message:@"shared successful." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] show];

        }else{

            [[[UIAlertView alloc] initWithTitle:@"shared cancel." message:@"shared cancel." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] show];

        }

    };

    [viewControllerpresentViewController:vc animated:YES completion:nil];

}

Demo地址:https://github.com/jayZhangh/PhotosFrameworkBasicUsage.git

相关文章

网友评论

      本文标题:iOS系统原生分享-UIActivityViewControll

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