[WXApi registerApp:weixinAppKey];
if(![WXApi isWXAppInstalled]){
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"信息" message:@"未安装微信,不能分享" delegate:nil cancelButtonTitle:@"我知道了" otherButtonTitles:nil];
[alert show];
return;
}
if(![WXApi isWXAppSupportApi]){
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"信息" message:@"微信不支持该API" delegate:nil cancelButtonTitle:@"我知道了" otherButtonTitles:nil];
[alert show];
return;
}
WXMediaMessage *message = [WXMediaMessage message];
[message setThumbImage:[UIImage imageNamed:@"logo.png"]];
NSString *str=@"";
message.title=str;
message.description=str;
//链接
WXWebpageObject *webObj = [WXWebpageObject object];
webObj.webpageUrl = downloadURL;
message.mediaObject = webObj;
//图片
// WXImageObject *imageObject = [WXImageObject object];
// UIImage *image = [UIImage imageNamed:@"install.png"];
// imageObject.imageData = UIImagePNGRepresentation(image);
// message.mediaObject = imageObject;
SendMessageToWXReq* request = [[SendMessageToWXReq alloc] init];
request.bText = NO;
request.message = message;
request.scene = WXSceneTimeline;
[WXApi sendReq:request];
通过以上分享于朋友圈或朋友时,隐藏了一个小问题并且微信api包不提供错误信息,即[message setThumbImage:[UIImage imageNamed:@"logo.png"]],当缩略图过大,将分享不成功,即无法打开微信客户端
解决办法:换图,改变缩略图大小