iOS开发之笔记摘录

iOS之系统分享

2017-08-31  本文已影响5409人  平安喜乐698
目录


                // 分享标题(可选)
                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;
}
上一篇下一篇

猜你喜欢

热点阅读