uni-app 3.0.1 android11 调起微信分享发送图片给好友失败,分享到朋友圈也失败

uni-app 3.0.1 android11 调起微信分享发送图片给好友失败,分享到朋友圈也失败

开发环境 版本号 项目创建方式
Windows Windows 10 家庭中文版 HBuilderX

产品分类:uniapp/App

PC开发环境操作系统:Windows

HBuilderX类型:正式

HBuilderX版本号:3.1.2

手机系统:Android

手机系统版本号:Android 11

手机厂商:小米

手机机型:Redmi Note 8 Pro

页面类型:vue

打包方式:云端

示例代码:

setTimeout(function() {
    uni.share({  
        provider: "weixin",  
        scene: "WXSceneSession",  
        type: 2,  
        // href: 'http://baidu.com',  
        title: '',  
        imageUrl: that.cutImage,  
        success: function(res) {  
            that.$refs.uToast.show({  
                title: JSON.stringify(err)  
            })  
        },  
        fail: function(err) {  
            that.$refs.uToast.show({  
                title: JSON.stringify(err)  
            })  
        }  
    });  
}, 1200)
setTimeout(function() {  
    uni.share({  
        provider: "weixin",  
        scene: "WXSenceTimeline",  
        type: 2,  
        // href: 'http://baidu.com',  
        title: that.nickName + '向您分享了他临摹的字',  
        imageUrl: that.cutImage,  
        success: function(res) {  
            that.$refs.uToast.show({  
                title: JSON.stringify(err)  
            })  
        },  
        fail: function(err) {  
            that.$refs.uToast.show({  
                title: JSON.stringify(err)  
            })  
        }  
    });  
}, 1200)

操作步骤:

setTimeout(function() {
    uni.share({  
        provider: "weixin",  
        scene: "WXSceneSession",  
        type: 2,  
        // href: 'http://baidu.com',  
        title: '',  
        imageUrl: that.cutImage,  
        success: function(res) {  
            that.$refs.uToast.show({  
                title: JSON.stringify(err)  
            })  
        },  
        fail: function(err) {  
            that.$refs.uToast.show({  
                title: JSON.stringify(err)  
            })  
        }  
    });  
}, 1200)
setTimeout(function() {  
    uni.share({  
        provider: "weixin",  
        scene: "WXSenceTimeline",  
        type: 2,  
        // href: 'http://baidu.com',  
        title: that.nickName + '向您分享了他临摹的字',  
        imageUrl: that.cutImage,  
        success: function(res) {  
            that.$refs.uToast.show({  
                title: JSON.stringify(err)  
            })  
        },  
        fail: function(err) {  
            that.$refs.uToast.show({  
                title: JSON.stringify(err)  
            })  
        }  
    });  
}, 1200)

更多关于uni-app 3.0.1 android11 调起微信分享发送图片给好友失败,分享到朋友圈也失败的实战教程也可以访问 https://www.itying.com/category-93-b0.html

5 回复

我也遇到了 请问你解决了吗

更多关于uni-app 3.0.1 android11 调起微信分享发送图片给好友失败,分享到朋友圈也失败的实战教程也可以访问 https://www.itying.com/category-93-b0.html


3.1.4已修复

3.1.4出现了分享本地图片无法调起微信,但是触发了app.vue的生命周期 看样子跟你这是一样的问题

Android11分享图分享到QQ 文件不存在或为空

根据您提供的代码和问题描述,以下是可能导致微信分享失败的原因及解决方案:

  1. 图片路径问题:
  • 确保that.cutImage是有效的本地文件路径(如/storage/emulated/...格式)
  • 如果是网络图片,需要先下载到本地再分享
  1. 微信SDK配置问题:
  • 检查manifest.json中已正确配置微信AppID
  • 确保已勾选微信分享权限
  1. Android 11权限问题:
  • 需要在manifest.json中添加:
"android-permission": [
    "android.permission.READ_EXTERNAL_STORAGE",
    "android.permission.WRITE_EXTERNAL_STORAGE"
]
  1. 代码问题:
  • 成功回调中使用了未定义的err变量(应改为res
  • WXSenceTimeline拼写错误,应为WXSceneTimeline

建议修改后的代码:

// 分享给好友
uni.share({
    provider: "weixin",
    scene: "WXSceneSession",
    type: 2,
    imageUrl: that.cutImage,
    success: function(res) {
        console.log("分享成功", res);
    },
    fail: function(err) {
        console.log("分享失败", err);
    }
});

// 分享到朋友圈
uni.share({
    provider: "weixin",
    scene: "WXSceneTimeline",
    type: 2,
    title: that.nickName + '向您分享了他临摹的字',
    imageUrl: that.cutImage,
    success: function(res) {
        console.log("分享成功", res);
    },
    fail: function(err) {
        console.log("分享失败", err);
    }
});
回到顶部