在做iOS分享小程序的功能,需求是分享到微信聊天框内容,应当根据当前的商品来动态显示。
实现的过程中,发现分享出来的微信聊天框内容图片非常模糊。经过排查发现,
具体场景:点击分享,直接跳转到微信的选择聊天界面,发送的内容为标题+动态网络图片,用户点击后,打开小程序。
有问题的 图片模糊的相关代码如下:
-(void)shareClick{
NSString* path =[NSString stringWithFormat: @"http://feiyangimage.oss-cn-shanghai.aliyuncs.com/item/1576141433704930.png",[self.title UTF8String]];
NSURL* url = [NSURL URLWithString:[path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSData* data = [NSData dataWithContentsOfURL:url];
UIImage *image = [[UIImage alloc] initWithData:data];
UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
UMShareMiniProgramObject *shareObject = [UMShareMiniProgramObject shareObjectWithTitle:@"韩版长款羊毛围巾 冬季格子百搭护颈披肩两用款" descr:@"" thumImage:image];
shareObject.webpageUrl = @"兼容微信低版本网页地址";
shareObject.userName = @"gh_1768028640ec";
NSString *sharePath = [NSString stringWithFormat:@"pages/Goods/GoodsDes/index?id=%@&name=%@",self.goodsId,@"韩版长款羊毛围巾 冬季格子百搭护颈披肩两用款"];// 小程序路径
shareObject.path = sharePath;
messageObject.shareObject = shareObject;
shareObject.miniProgramType = UShareWXMiniProgramTypeRelease; // 可选体验版和开发板
//调用分享接口
[[UMSocialManager defaultManager] shareToPlatform:UMSocialPlatformType_WechatSession messageObject:messageObject currentViewController:nil completion:^(id result, NSError *error) {
[self shareResult:result error:error];
}];
}
// 分享回调
-(void)shareResult:(id)result error:(NSError*)error
{
NSLog(@"result为--%@----error为%@",result,error);
if (!error)
{
[FYProgressHUDManager failedToastHudShowWithTitle:@"分享成功" AfterDelay:1.5];
}
else
{
[FYProgressHUDManager failedToastHudShowWithTitle:@"分享失败" AfterDelay:1.5];
}
}
经过排查发现,问题具体原因是:
分享的出来的内容是缩略图,不是高清图,增加一行代码即可。shareObject.hdImageData = data;
解决方法如下:
-(void)shareClick{
NSString* path =[NSString stringWithFormat: @"http://feiyangimage.oss-cn-shanghai.aliyuncs.com/item/1576141433704930.png",[self.title UTF8String]];
NSURL* url = [NSURL URLWithString:[path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSData* data = [NSData dataWithContentsOfURL:url];
UIImage *image = [[UIImage alloc] initWithData:data];
UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
UMShareMiniProgramObject *shareObject = [UMShareMiniProgramObject shareObjectWithTitle:@"韩版长款羊毛围巾 冬季格子百搭护颈披肩两用款" descr:@"" thumImage:image];
shareObject.webpageUrl = @"兼容微信低版本网页地址";
shareObject.userName = @"gh_1768028640ec";
NSString *sharePath = [NSString stringWithFormat:@"pages/Goods/GoodsDes/index?id=%@&name=%@",self.goodsId,@"韩版长款羊毛围巾 冬季格子百搭护颈披肩两用款"];// 小程序路径
shareObject.path = sharePath;
messageObject.shareObject = shareObject;
shareObject.hdImageData = data;
shareObject.miniProgramType = UShareWXMiniProgramTypeRelease; // 可选体验版和开发板
// 调用分享接口
[[UMSocialManager defaultManager] shareToPlatform:UMSocialPlatformType_WechatSession messageObject:messageObject currentViewController:nil completion:^(id result, NSError *error) {
[self shareResult:result error:error];
}];
}
// 分享回调
-(void)shareResult:(id)result error:(NSError*)error
{
NSLog(@"result为--%@----error为%@",result,error);
if (!error)
{
[FYProgressHUDManager failedToastHudShowWithTitle:@"分享成功" AfterDelay:1.5];
}
else
{
[FYProgressHUDManager failedToastHudShowWithTitle:@"分享失败" AfterDelay:1.5];
}
}
网友评论