// 1、设置分享的内容,并将内容添加到数组中
NSArray *activityItemsArray = @[self.model.content];
NSArray *activityArray = @[];
// 2、初始化控制器,添加分享内容至控制器
UIActivityViewController *activityVC = [[UIActivityViewController alloc]initWithActivityItems:activityItemsArray applicationActivities:activityArray];
activityVC.modalInPopover = YES;
// 3、设置回调
if ([UIDevice currentDevice].systemVersion.floatValue >= 8.0) {
// ios8.0 之后用此方法回调
UIActivityViewControllerCompletionWithItemsHandler itemsBlock = ^(UIActivityType __nullable activityType, BOOL completed, NSArray * __nullable returnedItems, NSError * __nullable activityError){
NSLog(@"activityType == %@",activityType);
if (completed == YES) {
NSLog(@"completed");
}else{
NSLog(@"cancel");
}
};
activityVC.completionWithItemsHandler = itemsBlock;
}else{
// ios8.0 之前用此方法回调
UIActivityViewControllerCompletionHandler handlerBlock = ^(UIActivityType __nullable activityType, BOOL completed){
NSLog(@"activityType == %@",activityType);
if (completed == YES) {
NSLog(@"completed");
}else{
NSLog(@"cancel");
}
};
activityVC.completionHandler = handlerBlock;
}
// 4、调用控制器
[self presentViewController:activityVC animated:YES completion:nil];
网友评论