1. 导入Social.framework 库
2. 代码
- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
{
//分享的标题
NSString *text =@"分享的标题。";
//分享的图片
// UIImage *image= [UIImage imageNamed:@"分享的图片.png"];
//分享的url
NSURL*url = [NSURLURLWithString:@"分享的url"];
//把分项的文字, 图片, 链接放入数组
NSArray*activityItems =@[text,image,url];
UIActivityViewController *activityVC = [[UIActivityViewController alloc]initWithActivityItems:activityItems applicationActivities:nil];
//不出现在活动项目
activityVC.excludedActivityTypes = @[UIActivityTypePrint, UIActivityTypeCopyToPasteboard,UIActivityTypeAssignToContact,UIActivityTypeSaveToCameraRoll];
//弹出分享的页面
[self presentViewController:activityVC animated:YES completion:nil];
// 分享后回调
activityVC.completionWithItemsHandler= ^(UIActivityType _NullableactivityType,BOOLcompleted,NSArray*_NullablereturnedItems,NSError*_NullableactivityError) {
if(completed) {
NSLog(@"completed");
//分享成功
}else {
NSLog(@"cancled");
//分享取消
}
};
}
网友评论