一开始咱们想到的是可能微信这边的Bug,但细想一下应该不是。由于可能涉及到了IOS的底层原理的问题,多是不受微信所控。(有问题欢迎拍砖)php
出现问题得解决问题啊,不能把问题晾在那边无论,这是程序员的尊严!html
我这个是SPA应用,因此拿其中一个vue项目来作探讨,其余SPA应用同理vue
咱们把全部设置都检查了一遍,最终发现是当前路由location.href不一致的问题ios
咱们能够去尝试一下去到具体某个页面:程序员
在Android下微信复制当前连接而后粘贴到输入框里,会发现路由是具体到某个路由。例如:www.xxxx.com/news/xxxx浏览器
在IOS下微信复制当前连接而后粘贴到输入框里,会发现路由是首页。例如:wwwx.xxxx.com/index微信
因此问题就定位在了url上,此次我只拿调取扫一扫功能,其他功能自行加上。app
首先在index.html页面中引入JSSDK文件url
而后在App.vue文件中.net
if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) { const url = location.href const res = await getSignature(url) //获取设置config的参数 let { timestamp, noncestr, signature, appId } = res.data wx.config({ beta: true, debug: false, appId: appId, timestamp: timestamp, nonceStr: noncestr, signature: signature, jsApiList: ['scanQRCode'] }); wx.ready(function () { console.log('设备已经可使用') }) }
具体到某个页面的时候 例如:news下
if (/(Android)/i.test(navigator.userAgent)) { let url = location.href const res = await getSignature(url) //获取设置config的参数 let { timestamp, noncestr, signature, appId } = res.data wx.config({ beta: true, debug: false, appId: appId, timestamp: timestamp, nonceStr: noncestr, signature: signature, jsApiList: ['scanQRCode'] }); wx.ready(function () { console.log('设备已经可使用') }) }
这仅限
于在微信自带的游览器上。企业微信自带的游览器这方法是不行的。
经过微信企业浏览器扫码获取到的微信浏览器信息以下:(图片摘取于CSDN)
微信客户端扫码获取到的信息以下:
对比企业微信游览其和微信游览器的信息,多出了wxwork。那么咱们只须要添加多一个判断条件就行了
在App.vue文件中
if (/(wxwork)/i.test(navigator.userAgent)) { return } if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) { const url = location.href const res = await getSignature(url) //获取设置config的参数 let { timestamp, noncestr, signature, appId } = res.data wx.config({ beta: true, debug: false, appId: appId, timestamp: timestamp, nonceStr: noncestr, signature: signature, jsApiList: ['scanQRCode'] }); wx.ready(function () { console.log('设备已经可使用') }) }
在news文件中
if (/(Android)/i.test(navigator.userAgent) || /(wxwork)/i.test(navigator.userAgent)) { let url = location.href const res = await getSignature(url) //获取设置config的参数 let { timestamp, noncestr, signature, appId } = res.data wx.config({ beta: true, debug: false, appId: appId, timestamp: timestamp, nonceStr: noncestr, signature: signature, jsApiList: ['scanQRCode'] }); wx.ready(function () { console.log('设备已经可使用') }) }