We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
import Taro from "@tarojs/taro" interface IDeviceInfo extends Omit<Taro.getDeviceInfo.Result, 'deviceAbi' | 'CPUType'> { } // 获取设备基础信息,兼容新旧 API export function getDeviceInfo(): IDeviceInfo { // 先判断 Taro.canIUse 能否使用新的 API if (Taro.canIUse('getDeviceInfo')) { return Taro.getDeviceInfo() } return Taro.getSystemInfoSync() } // 获取窗口信息,兼容新旧 API export function getWindowInfo(): Taro.getWindowInfo.Result { // 先判断 Taro.canIUse 能否使用新的 API if (Taro.canIUse('getWindowInfo')) { return Taro.getWindowInfo() } return Taro.getSystemInfoSync() } // 获取应用基础信息,兼容新旧 API export function getAppBaseInfo(): Taro.getAppBaseInfo.Result { // 先判断 Taro.canIUse 能否使用新的 API if (Taro.canIUse('getAppBaseInfo')) { return Taro.getAppBaseInfo() } return Taro.getSystemInfoSync() }
代码中通过 getSystemInfoSync 获取相应信息的地方,使用上面的方法兼容一下新老 api
The text was updated successfully, but these errors were encountered:
@Alex-huxiyang Taro.getDeviceInfo 在支付宝小程序上获取的信息不对,需要单独判断下
// 获取设备基础信息,兼容新旧 API export function getDeviceInfo(): IDeviceInfo { const isWeApp = Taro.getEnv() === Taro.ENV_TYPE.WEAPP // 先判断 Taro.canIUse 能否使用新的 API if (isWeApp && Taro.canIUse('getDeviceInfo')) { return Taro.getDeviceInfo() } return Taro.getSystemInfoSync() }
给 Taro 提了个 issue NervJS/taro#17309
Sorry, something went wrong.
看你们的对话,似乎是支付宝getDeviceAPi的问题?
是的,只能判断在微信小程序才用 Taro.getDeviceInfo(),其他环境下还是用 Taro.getSystemInfoSync() 获取设备信息,可以暂时规避这个问题
Taro.getDeviceInfo()
Taro.getSystemInfoSync()
Alex-huxiyang
Successfully merging a pull request may close this issue.
这个功能解决了什么问题?
你期望的组件设计是怎样的?
代码中通过 getSystemInfoSync 获取相应信息的地方,使用上面的方法兼容一下新老 api
The text was updated successfully, but these errors were encountered: