iOS 系统分享

作者: 彼岸花下的暗影 | 来源:发表于2019-05-23 15:32 被阅读0次
    // 1、设置分享的内容,并将内容添加到数组中
        NSArray *activityItemsArray = @[self.model.content];
        NSArray *activityArray = @[];
        
        // 2、初始化控制器,添加分享内容至控制器
        UIActivityViewController *activityVC = [[UIActivityViewController alloc]initWithActivityItems:activityItemsArray applicationActivities:activityArray];
        activityVC.modalInPopover = YES;
        // 3、设置回调
        if ([UIDevice currentDevice].systemVersion.floatValue >= 8.0) {
            // ios8.0 之后用此方法回调
            UIActivityViewControllerCompletionWithItemsHandler itemsBlock = ^(UIActivityType __nullable activityType, BOOL completed, NSArray * __nullable returnedItems, NSError * __nullable activityError){
                NSLog(@"activityType == %@",activityType);
                if (completed == YES) {
                    NSLog(@"completed");
                }else{
                    NSLog(@"cancel");
                }
            };
            activityVC.completionWithItemsHandler = itemsBlock;
        }else{
            // ios8.0 之前用此方法回调
            UIActivityViewControllerCompletionHandler handlerBlock = ^(UIActivityType __nullable activityType, BOOL completed){
                NSLog(@"activityType == %@",activityType);
                if (completed == YES) {
                    NSLog(@"completed");
                }else{
                    NSLog(@"cancel");
                }
            };
            activityVC.completionHandler = handlerBlock;
        }
        // 4、调用控制器
        [self presentViewController:activityVC animated:YES completion:nil];
    

    相关文章

      网友评论

        本文标题:iOS 系统分享

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