uni-app uni.share分享小程序一直提示不支持的分享类型

uni-app uni.share分享小程序一直提示不支持的分享类型

开发环境 版本号 项目创建方式
Windows Windows 11 HBuilderX
Android Android 14
OPPO
oppok11
vue vue2

操作步骤:

  • 不支持的分享类型

预期结果:

  • 正常分享

实际结果:

  • 分享失败不支持的分享类型

bug描述:

uni.share({
provider: 'weixin',
scene: "WXSceneSession",
type: 5,
imageUrl: 'https://qiniu-web-assets.dcloud.net.cn/unidoc/zh/share-logo@3.png',
title: '欢迎体验uniapp',
miniProgram: {
id: 'gh_df1c17e407fd',
path: 'pages/index/index',
type: 0,
webUrl: 'http://uniapp.dcloud.io'
},
success: ret => {
console.log(JSON.stringify(ret));
}
});

更多关于uni-app uni.share分享小程序一直提示不支持的分享类型的实战教程也可以访问 https://www.itying.com/category-93-b0.html

1 回复

更多关于uni-app uni.share分享小程序一直提示不支持的分享类型的实战教程也可以访问 https://www.itying.com/category-93-b0.html


在使用 uni.share 进行分享时,如果提示“不支持的分享类型”,通常是因为分享的内容类型不符合微信小程序的要求,或者分享的参数配置不正确。以下是一些可能的原因和解决方法:

1. 检查分享类型

微信小程序支持的分享类型包括:

  • 文本text
  • 图片image
  • 链接link

确保你使用的分享类型是上述之一。

2. 检查分享参数

uni.share 的参数需要根据分享类型进行正确配置。以下是一些常见的参数配置示例:

分享文本

uni.share({
    provider: 'weixin',
    scene: 'session', // 分享到聊天界面
    type: 'text',
    summary: '这是分享的文本内容',
    success: function (res) {
        console.log('分享成功');
    },
    fail: function (err) {
        console.log('分享失败', err);
    }
});

分享图片

uni.share({
    provider: 'weixin',
    scene: 'session', // 分享到聊天界面
    type: 'image',
    imageUrl: 'https://example.com/image.png',
    success: function (res) {
        console.log('分享成功');
    },
    fail: function (err) {
        console.log('分享失败', err);
    }
});

分享链接

uni.share({
    provider: 'weixin',
    scene: 'session', // 分享到聊天界面
    type: 'link',
    title: '分享标题',
    summary: '分享描述',
    href: 'https://example.com',
    imageUrl: 'https://example.com/image.png',
    success: function (res) {
        console.log('分享成功');
    },
    fail: function (err) {
        console.log('分享失败', err);
    }
});

3. 检查小程序权限

确保小程序已经配置了分享权限。在微信公众平台上,检查小程序的权限设置,确保分享功能已经开启。

4. 检查 uni.share 的兼容性

uni.share 在不同平台上的支持情况可能有所不同。确保你使用的分享类型在当前平台(如微信小程序)上是被支持的。

5. 调试和日志

如果问题仍然存在,可以使用 console.log 打印出 uni.share 的参数和返回的错误信息,进一步排查问题。

6. 更新 uni-app SDK

确保你使用的 uni-app SDK 是最新版本,因为旧版本可能存在一些已知的 bug 或兼容性问题。

示例代码

以下是一个完整的示例代码,展示如何正确使用 uni.share 进行分享:

uni.share({
    provider: 'weixin',
    scene: 'session', // 分享到聊天界面
    type: 'link',
    title: '分享标题',
    summary: '分享描述',
    href: 'https://example.com',
    imageUrl: 'https://example.com/image.png',
    success: function (res) {
        console.log('分享成功');
    },
    fail: function (err) {
        console.log('分享失败', err);
    }
});
回到顶部