解决IOS微信SDK初始化失败

项目中有一个微信分享功能, 需要用到微信SDK,初始化代码如下

 //初始化sdk配置
    initJssdkShare: function(callback, url) {
        postRequest(global_.API_URLS.getJsConfig, {curUrl: url}).then((res) => {
			if (res.resultCode == "1") {
			    jweixin.config({
			        debug: false,
			        appId: res.object.appId,
			        timestamp: res.object.timestamp,
			        nonceStr: res.object.nonceStr,
			        signature: res.object.signature,
			        jsApiList: [
			            'checkJsApi',
			            'onMenuShareTimeline',
			            'onMenuShareAppMessage',
			            'getLocation',
						'closeWindow',
						'showMenuItems',
						'showOptionMenu',
						'hideMenuItems'
			        ]
			    });
				jweixin.ready(() => {
					console.log('wx ready')
					if (callback) {
						console.log("配置完成,执行功能")
					    callback(res.data);
					}
				 });
			   
			}	
        });

真机操作中发现, 安卓端可以正常初始化成功, IOS服务端一直出现签名认证失败,最后发现是IOS授权的URL导致的。
解决方案: 前端项目路由时 记录当前URL至缓存中, IOS只保留首次进入页面的URL,安卓端实时刷新,微信SDK初始化时, 认证URL从缓存中获取。

// 路由全局拦截器 在这里处理登录、授权等相关操作
router.beforeEach(function(to, from, next) {
	console.log('前置守卫')

	//1. 判断是否为刷新页面
	if(to.page){
		//2. 判断是否为ios 如果为ios且有缓存url 则不做处理
		var isIOS = /(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent);
		//var isIOS = true
		console.log("当前系统: "+navigator.userAgent+", isIOS: "+isIOS)
		if(isIOS){
			var syncUrl = uni.getStorageSync("current_url")
			console.log("当前缓存链接:"+syncUrl)
			if(!syncUrl){
				console.log(global_.H5_URL+"/wx"+to.page)
				uni.setStorageSync("current_url",global_.H5_URL+"/wx"+to.page)
			}
		}else{
			console.log(global_.H5_URL+"/wx"+to.page)
			uni.setStorageSync("current_url",global_.H5_URL+"/wx"+to.page)
		}
		
	}else{
	//页面刷新 清除当前缓存url
		console.log("首次进入: " + location.href.split('#')[0])
		uni.setStorageSync("current_url",location.href.split('#')[0])
	}
	next()
})
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值