常用的分享实现方法包括:
- 系统分享组件;
uniShare SDK
调用;
二、系统分享组件
uni.shareWithSystem(OBJECT)
调用系统分享组件发送分享消息,不需要配置分享SDK。分享效果为标题+链接+图片
形式,不支持摘要。
注意事项⚠️
Android
端当msg
参数中设置图片(imageUrl
属性)时,分享类型自动变为为image
,在分享时可能只会发送图片(如微信);没有设置图片时分享类型则认为是文本text
。Android
端高版本无法分析私有路径的图片,只能分享来自相册的图片(使用uni.chooseImage
选择图像时请设置为原图)。iOS
端不同的分享程序对分享内容有要求,如微信分享时必须添加链接地址href
,否则微信分享失败。 注:iOS8.0
及以上系统触发成功回调则表示发送消息成功。
// iOS应用系统自带分享方式
uni.shareWithSystem({
type: "text",
summary: this.detailData.resourceName + summary,
href: href,
imageUrl: "../../../static/logo.png