本文主要分享UIActivityViewController使用的小坑F教怠!
如果分享的是二進(jìn)制文件數(shù)據(jù)伍纫,不會(huì)出現(xiàn)微信宗雇、QQ、CSDN等分享莹规,并且左上方不會(huì)自動(dòng)解析文件名字和縮略圖
NSData *data = [NSData dataWithContentsOfURL:self.fileURL];
NSArray*activityItems = @[data];
UIActivityViewController *activityVC = [[UIActivityViewController alloc]initWithActivityItems:activityItems applicationActivities:nil];
[[UIApplication sharedApplication].delegate.window.rootViewController presentViewController:activityVC animated:YES completion:nil];
// 分享之后的回調(diào)
activityVC.completionWithItemsHandler = ^(UIActivityType _Nullable activityType,BOOL completed,NSArray*_Nullable returnedItems,NSError*_Nullable activityError) {
if (completed) {
NSLog(@"分享完成");
}else {
NSLog(@"分享未完成");
}
};
如果分享的是赔蒲,出現(xiàn)微信、QQ良漱、CSDN等分享舞虱,左上方也會(huì)自動(dòng)解析文件名字、縮略圖以及文件大小
NSArray*activityItems = @[self.fileURL];
UIActivityViewController *activityVC = [[UIActivityViewController alloc]initWithActivityItems:activityItems applicationActivities:nil];
[[UIApplication sharedApplication].delegate.window.rootViewController presentViewController:activityVC animated:YES completion:nil];
// 分享之后的回調(diào)
activityVC.completionWithItemsHandler = ^(UIActivityType _Nullable activityType,BOOL completed,NSArray*_Nullable returnedItems,NSError*_Nullable activityError) {
if (completed) {
NSLog(@"分享完成");
}else {
NSLog(@"分享未完成");
}
};