iOS之系统分享

作者: 平安喜乐698 | 来源:发表于2017-08-31 17:06 被阅读5409次
    目录
    
    
    
                    // 分享标题(可选)
                    NSString *shareTitle = @"";
                    // 分享右下角图片
                    UIImage *shareImage = [UIImage imageNamed:@""];
                    // 分享url(没提供url时仅显示图片,提供url后和友盟的web链接类似)
                    NSURL *shareUrl = [NSURL URLWithString:@"分享跳转"];
                    NSArray *activityItems = @[shareTitle,
                                               shareImage,
                                               shareUrl,
                                               ];
    
                    UIActivityViewController *activityVC = [[UIActivityViewController alloc]initWithActivityItems:activityItems applicationActivities:nil];
                    if ([activityVC respondsToSelector:@selector(popoverPresentationController)]) {
                        activityVC.popoverPresentationController.sourceView = [strongSelf getCurretViewController].view;
                        [activityVC.popoverPresentationController setPermittedArrowDirections:0];
                        activityVC.popoverPresentationController.sourceRect = CGRectMake(0, kScreenHeight, kScreenWidth, kScreenHeight);
                    }
                    [self presentViewController:activityVC animated:YES completion:nil];
                    
                    activityVC.completionWithItemsHandler = ^(UIActivityType  _Nullable   activityType,
                                                              BOOL completed,
                                                              NSArray * _Nullable returnedItems,
                                                              NSError * _Nullable activityError) {
                        if(activityError){
                            self.shareErrorBlock(@"分享出错");
                        }else{
                            self.shareSuccessBlock(@"分享成功");
                        }
                        NSLog(@"activityType: %@,\n completed: %d,\n returnedItems:%@,\n activityError:%@",activityType,completed,returnedItems,activityError);
                    };
                    activityVC.excludedActivityTypes = [self excludetypeArray];
    
    // 返回不允许使用的功能
    -(NSArray *)excludetypeArray{
        NSMutableArray *excludeTypesM =  [NSMutableArray arrayWithArray:@[
    //            UIActivityTypePostToFacebook,
    //            UIActivityTypePostToTwitter,
    //            UIActivityTypePostToWeibo,
    //            UIActivityTypeMessage,
    //            UIActivityTypeMail,
    //            UIActivityTypePrint,
    //            UIActivityTypeCopyToPasteboard,
    //            UIActivityTypeAssignToContact,
    //            UIActivityTypeSaveToCameraRoll,
    //            UIActivityTypeAddToReadingList,
    //            UIActivityTypePostToFlickr,
    //            UIActivityTypePostToVimeo,
    //            UIActivityTypePostToTencentWeibo,
    //            UIActivityTypeAirDrop,
    //            UIActivityTypeOpenInIBooks,
        ]];
        if (@available(iOS 11.0, *)) {
            [excludeTypesM addObject:UIActivityTypeMarkupAsPDF];
        }
        return excludeTypesM;
    }
    

    相关文章

      网友评论

        本文标题:iOS之系统分享

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