本文主要分享UIActivityViewController使用的小坑!!
如果分享的是二进制文件数据,不会出现微信、QQ、CSDN等分享,并且左上方不会自动解析文件名字和缩略图
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];
// 分享之后的回调
activityVC.completionWithItemsHandler = ^(UIActivityType _Nullable activityType,BOOL completed,NSArray*_Nullable returnedItems,NSError*_Nullable activityError) {
if (completed) {
NSLog(@"分享完成");
}else {
NSLog(@"分享未完成");
}
};
不出现第三方app的分享效果图
如果分享的是,出现微信、QQ、CSDN等分享,左上方也会自动解析文件名字、缩略图以及文件大小
NSArray*activityItems = @[self.fileURL];
UIActivityViewController *activityVC = [[UIActivityViewController alloc]initWithActivityItems:activityItems applicationActivities:nil];
[[UIApplication sharedApplication].delegate.window.rootViewController presentViewController:activityVC animated:YES completion:nil];
// 分享之后的回调
activityVC.completionWithItemsHandler = ^(UIActivityType _Nullable activityType,BOOL completed,NSArray*_Nullable returnedItems,NSError*_Nullable activityError) {
if (completed) {
NSLog(@"分享完成");
}else {
NSLog(@"分享未完成");
}
};
出现第三方app的分享效果图
网友评论