// 获取压缩包数据
NSArray *activityItems = @[[NSURL fileURLWithPath:self.ui_path]];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
// 兼容ipad
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
activityVC.popoverPresentationController.sourceView = Sub_Controller.view;
activityVC.popoverPresentationController.sourceRect = CGRectMake(Sub_Controller.view.frame.size.width/2.0, Sub_Controller.view.frame.size.height/2.0, 1.0, 1.0);
activityVC.popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirectionAny;
}
// 去除一些不需要的图标选项
//activityVC.excludedActivityTypes = @[UIActivityTypePostToFacebook, UIActivityTypePostToWeibo, UIActivityTypePostToTencentWeibo];
// 成功失败的回调block
UIActivityViewControllerCompletionWithItemsHandler myBlock = ^(UIActivityType __nullable activityType,
BOOL completed, NSArray * __nullable returnedItems,
NSError * __nullable activityError) {
if (completed) {
CHLog(@"completed");
}
else {
CHLog(@"canceled");
}
};
activityVC.completionWithItemsHandler = myBlock;
[Sub_Controller presentViewController:activityVC animated:YES completion:nil];