最近使用uni-app开发了一个微信小程序使用的功能。需要用到分享给微信好友的功能。如果不做如下设置的话,本身微信默认的分享只是当前页面。
/**
* 分享
*/
initShare() {
let this_ = this;
var linkUrl =this_.GLOBAL.H5_URL + '/wx/pages/wx/service/ImmigrationServices/index;
console.log(linkUrl)
//设置分享链接,如标题,描述信息以及图片
var shareData = {
title: 'space-X火星移民服务',
desc: 'Welcome to Mars...',
link: linkUrl,
img: ''
};
this_.wechat.share(shareData);
},
上图中的linkUrl就是所要分享的其他页面地址。设置完成之后,Android手机可以正常使用,但iOS却不可以,转发给好友的链接中的标题、描述,依然不是我自定义的shareData中的信息。
在百度上搜到了一个实用的方法:
在进入这个页面(initShare方法所在的页面)的页面跳转方式,从uni.navigateTo换成JS原生的跳转方式window.location.href
提交代码,发行,测试——>成功啦!
这里需要注意的是,window.location.href里的路径需要用全路径,包含域名的路径。
引用自一位好心人的博客:
https://www.cnblogs.com/yeziyou/p/13790261.html