uniapp分享图片使用uni.share()分享到新浪微博失败

前言

uni-app开发APP应用时,使用uni.share(OBJECT)分享图文,在APP端新浪微博的分享配置已经添加。在分享到到新浪微博时,若带图片分享,ios端分享正常,Android端会分享失败,提示:share:fail分享图片仅支持本地路径。

知识点

关于uni-app分享功能的详细信息,可以到uni-app官网查看。

解决方案

使用uni.downloadFile()将要图片下载到本地,然后再调用uni.share(OBJECT)分享。

具体演示代码

uni.downloadFile({
  url: shareImageUrl,
  success: (res) => {
    if (res.statusCode === 200) {
  	  this.shareConfig(res.tempFilePath);
    }else{
      this.shareConfig('');
    }
    ,fail: (res) => {
      this.shareConfig('');
    }  
});
shareConfig(sharePicUrl){
  uni.share({
    provider: 'sinaweibo',
    scene: '',
    type: 0, //默认0:图文
    href: 'www.baidu.com',
    title: '分享标题',
    summary: '分享标题',
    imageUrl: sharePicUrl,
    success: function (res) {
      console.log("success:" + JSON.stringify(res));
    },
    fail: function (err) {
      console.log("fail:" + JSON.stringify(err));
    }
  });
}

猜你喜欢

转载自blog.csdn.net/loveliqi/article/details/126388089