iOS系统分享

效果图


iOS系统分享_第1张图片
FB5461D056EE5F72E20D9155920AAFD5.jpg

直接代码_

    NSMutableArray *sharingItems = [NSMutableArray new];
    NSString *textToShare = [NSString stringWithFormat:@"%@", text?text:[NSString CFBundleDisplayName]];
    NSURL *website = [NSURL URLWithString:url?url:@""];
    UIImage *shareImage = image?image:[UIImage imageNamed:@"share_app_icon"];
    if (textToShare) {
        [sharingItems addObject:textToShare];
    }
    if (website) {
        [sharingItems addObject:website];
    }
    if (shareImage) {
        [sharingItems addObject:shareImage];
    }
    TUSafariActivity *activity = [[TUSafariActivity alloc] init];//第三方库
    UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:sharingItems applicationActivities:@[activity]];
    // 去掉不显示项
    NSArray *excludeActivities = @[UIActivityTypePostToWeibo,
                                   UIActivityTypePostToFlickr,
                                   UIActivityTypePostToVimeo,
                                   UIActivityTypePostToTencentWeibo,
                                   UIActivityTypeAirDrop,
                                   UIActivityTypeOpenInIBooks,
                                   UIActivityTypeSaveToCameraRoll,
                                   UIActivityTypeAssignToContact,
                                   UIActivityTypePrint,
                                   ];
    activityVC.excludedActivityTypes = excludeActivities;
    activityVC.completionWithItemsHandler = ^(NSString *activityType, BOOL completed, NSArray *returnedItems, NSError *activityError) {
        dispatch_async(dispatch_get_main_queue(), ^{
        });
        if (completed)
        {
            NSLog(@"The Activity: %@ was completed", activityType);
        }
        else
        {
            NSLog(@"The Activity: %@ was NOT completed", activityType);
        }
    };
    [self presentViewController:activityVC animated:YES completion:nil];

你可能感兴趣的:(iOS系统分享)