iOS系统原生分享-UIActivityViewControll
+ (void)shareShowInViewController:(UIViewController*)viewController {
// 分享的title
NSString*textToShare =@"我是ZL,欢迎关注我!";
// 分享的图片
UIImage*imageToShare = [UIImageimageNamed:@"icon-60"];
// 分享的链接地址
NSURL *urlToShare = [NSURL URLWithString:@"https://www.jianshu.com/u/9cb1a1857948"];
// 顺序可以混乱,系统会自动识别类型
NSArray*activityItems =@[textToShare,urlToShare,imageToShare];
// 调起系统分享视图
UIActivityViewController *vc = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:@[]];
// 设置忽略分享App的属性
// vc.excludedActivityTypes = @[UIActivityTypePostToVimeo];
// 分享结果后的回调Block
vc.completionWithItemsHandler= ^(UIActivityType _NullableactivityType,BOOLcompleted,NSArray*_NullablereturnedItems,NSError*_NullableactivityError) {
NSLog(@"%@", activityType);
if(completed) {
[[[UIAlertView alloc] initWithTitle:@"shared successful." message:@"shared successful." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] show];
}else{
[[[UIAlertView alloc] initWithTitle:@"shared cancel." message:@"shared cancel." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] show];
}
};
[viewControllerpresentViewController:vc animated:YES completion:nil];
}
Demo地址:https://github.com/jayZhangh/PhotosFrameworkBasicUsage.git