NSURL *url = [NSURL URLWithString:self.imageViewShare];
NSData *data = [NSData dataWithContentsOfURL:url];
// 首先初始化activityItems参数
NSArray *activityItems = [[NSArray alloc]initWithObjects:self.titleShare,
[UIImage imageWithData:data], nil];
// 初始化一个UIActivityViewController
UIActivityViewController *activityVC = [[UIActivityViewController alloc]initWithActivityItems:activityItems applicationActivities:Nil];
// 写一个bolck,用于completionHandler的初始化
UIActivityViewControllerCompletionHandler myBlock = ^(NSString *activityType,BOOL completed) {
NSLog(@"%@", activityType);
if(completed) {
NSLog(@"completed\\");
} else
{
NSLog(@"cancled\\");
}
[activityVC dismissViewControllerAnimated:YES completion:Nil];
};
// 初始化completionHandler,当post结束之后(无论是done还是cancell)该blog都会被调用
activityVC.completionHandler = myBlock;
// 以模态方式展现出UIActivityViewController
[self presentViewController:activityVC animated:YES completion:Nil];
上面是所有的方法,直接复制即可,其中的图片是网络图片,需要现转化成NAData,再添加的数组中才能显示,直接添加是不显示的
网友评论