iOS UIActivityViewController分享

时间:2023-01-16 17:52:12

    NSArray*activityItems;

    //IMAGE

    if([strType isEqual:@"IMAGE"])

    {

        UIImage*imageToShare = _iv.image;

        activityItems [email protected][imageToShare];

    }else

    {

        NSURL*shareURL = [NSURL fileURLWithPath:strPDFURL];

        activityItems [email protected][shareURL];

    }

    UIActivityViewController *avc = [[UIActivityViewController alloc]initWithActivityItems:activityItems applicationActivities:nil];

    [self presentViewController:avc animated:YES completion:nil];

    [avc setCompletionWithItemsHandler:^(NSString*__nullableactivityType,BOOL completed,NSArray*__nullablereturnedItems,NSError*__nullableactivityError){

        if(completed) {

//分享成功

        }else{

//分享失败

          }

}