wepy
wepy copied to clipboard
await wepy.wx 失效(use-promisify)
Description
wepy2 use-promisify后调用 await wepy.wx.微信api没有返回,也没有报错,已知api包括:wepy.wx.checkSession;wepy.wx.getSetting;wepy.wx.chooseLocation。
Environment
- Platform: iOS
- Platform version: 13.1.3
- Wechat version: 7.0.8
- wepy-cli version: 2.0.0-alpha.12和2.0.0-alpha.20
- wepy version: 2.0.0-alpha.8和2.0.0-alpha.11
- other version: @wepy/use-promisify 2.0.0
Reproduce
const fun = () => { return new Promise(async (resolve, reject) => { try { await wepy.wx.微信api() resolve() } catch(e){} }) }
Observed Results
卡死了,不会触发catch,也不会resolve。 改成用 await wepy.promisify(wx.微信api, wx)() 就可以。
Expected Results
不会卡死可以使用
Relevant Code / Logs
chooseLocation (isShowHint = false) {
return new Promise(async (resolve, reject) => {
try {
// await wepy.wx.getSetting() || {}
// const { authSetting = {} } = await wepy.promisify(wx.getSetting, wx)() || {}
const { authSetting = {} } = await wepy.wx.getSetting() || {}
if (!authSetting['scope.userLocation']) {
try {
await wepy.wx.authorize({ scope: 'scope.userLocation' })
} catch (error) {
console.error('authorize', error)
if (isShowHint) {
const { confirm } = await wepy.wx.showModal({
title: '授权提示',
content: `需要设置定位信息授权才能获取周边地址信息`,
confirmText: '设置',
cancelText: '拒绝'
})
if (!confirm) {
reject(error)
} else {
wx.openSetting()
resolve()
}
return
}
reject(error)
// return
}
}
try {
// const { latitude = 0, longitude = 0, name = '', address = '' } = await wepy.promisify(wx.chooseLocation, wx)() || {}
const { latitude = 0, longitude = 0, name = '', address = '' } = await wepy.wx.chooseLocation() || {}
console.log({ latitude, longitude, name, address })
resolve({ latitude, longitude, name, address })
} catch (error) {
console.log(error)
resolve()
}
console.log('authSetting', authSetting)
} catch (error) {
console.error('chooseLocation', error)
reject(error)
}
})
},
```
额 不好意思 没看到你使用了use-promisify 我这边是使用了之后可以调用 建议升级下core版本测试下
core 版本是 alpha.11的了,之前没这个问题,但好像升级了微信版本之后就出现这个问题,建议你用真机试试 @jiangz153202
我也遇到了,小程序基础库版本2.9.3必现,wepy2 use-promisify的bug,解决方案:use-promisify/dist/index.js line:191 改为: var fixArgs = args.length > 2 ? args[0] : {};
@howarchou 2.9.3 以上的版本有问题吗?
@Gcaufy 有问题 我2.10.1 await wepy.wx.getSettings() 无返回
@DarrenHou1993
刚刚亲测可以执行,只不过是走到了catch 里面。 如果你用 await 的话,外层 try ... catch.. 一下看看。
这个问题我也出现了@Gcaufy
@wepy/use-promisify version": "2.0.6"
实测, try { check = await wepy.wx.checkSession() console.log('checkLocalSessionId pass') } catch (err) { check = err } 基础库 2.9.0 没有问题,2.9.1 必定卡死。 @Gcaufy
修复了吗 基础库 2.9.0以上还是没反应