美文网首页
iOS的系统分享功能[OC]

iOS的系统分享功能[OC]

作者: 辛乐 | 来源:发表于2019-07-16 17:15 被阅读0次
    + (void)shareWithTitle:(NSString *)title image:(UIImage *)image url:(NSString *)url target:(UIViewController *)target complete:(void (^)(BOOL isSuccess, UIActivityType type))complete
    {
        // 分享内容
        NSString *shareTitle = title;
        UIImage *shareImage = image;
        NSURL *shareUrl = [NSURL URLWithString:url];
        NSArray *activityItemsArray = @[shareTitle, shareImage, shareUrl];
        //
        UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:activityItemsArray applicationActivities:nil];
        activityVC.modalInPopover = YES;
        // 禁用分享渠道
        //    activityVC.excludedActivityTypes = @[UIActivityTypePrint, UIActivityTypeCopyToPasteboard, UIActivityTypeAssignToContact, UIActivityTypeSaveToCameraRoll, UIActivityTypeAddToReadingList, UIActivityTypePostToFlickr, UIActivityTypePostToVimeo, UIActivityTypeAirDrop, UIActivityTypeOpenInIBooks];
        
        //
        activityVC.completionWithItemsHandler = ^(UIActivityType  _Nullable activityType, BOOL completed, NSArray * _Nullable returnedItems, NSError * _Nullable activityError) {
            if (complete) {
                complete(completed, activityType);
            }
        };
        //
        [target presentViewController:activityVC animated:YES completion:nil];
    }
    

    相关文章

      网友评论

          本文标题:iOS的系统分享功能[OC]

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