iOS_微信分享(单张图片+文字)and 多张图片分享
2017-12-22 本文已影响895人
wahkim
1.单张图片 + 文字
SendMessageToWXReq* req = [[SendMessageToWXReq alloc] init];
req.bText = NO;//分享内容带图片和文字时必须为NO
UIImage *image = [UIImage imageNamed:@"opinion"];
WXImageObject *imageObject = [WXImageObject object];
imageObject.imageData = [NSData dataWithContentsOfURL:url];
WXMediaMessage *message = [WXMediaMessage message];
[message setThumbImage:image];
message.mediaObject = imageObject;
//如果分享的内容包括文字和,这个时候的文字不能使用req.text属性来接收,必须使用下边的两个属性
message.title = @"title";
message.description = @"description";
req.message = message;
req.scene = WXSceneSession;//好友
//req.scene = WXSceneTimeline;//朋友圈
[WXApi sendReq:req];
2.多张图片(微信开放平台没有提供接口,需使用系统自带接口)
UIImage *image1 = [UIImage imageNamed:@"opinion"];
UIImage *image2 = [UIImage imageNamed:@"current_1"];
NSArray *activityItems = @[image1,image2];
UIActivityViewController *activityVC = [[UIActivityViewController alloc]initWithActivityItems:activityItems applicationActivities:nil];
[self presentViewController:activityVC animated:TRUE completion:nil];
//回调
activityVC.completionWithItemsHandler = ^(UIActivityType _Nullable activityType, BOOL completed, NSArray * _Nullable returnedItems, NSError * _Nullable activityError) {
if (completed) {
}else{
}
};
参考文章:http://blog.csdn.net/u014220518/article/details/53465631