提一个bug,关于安卓手机调用wx.getSystemInfo的问题

发布于 6 年前作者 rli10131 次浏览最后编辑 6 年前来自 ask

首先这是一个随机bug,我们在华为荣耀9和金立上重现过.

在OnLoad的时候调用wx.getSystemInfo接口,代码如下:

wx.getSystemInfo({

     success: function(res) {

       self.data.screenWidth = res.windowWidth;

       self.data.screenHeight = res.windowHeight;

       console.log(“onLoad getSystemInfo success!”);

       console.log(“res.windowWidth:” + res.windowWidth);

       console.log(“res.windowHeight:” + res.windowHeight);

     },

     fail: function (res){

 

       console.log(“getSystemInfo fail!”);

     }

   })

系统打印结果是

onLoad getSystemInfo success!

res.windowWidth:0

res.windowHeight:0

换句话说就是:获取窗口的宽高失败了,但是却走了success回调.

5 回复
chaozou
chaozou1 楼6 年前

安卓部分手机会出现,ios不会

xiulancheng
xiulancheng2 楼6 年前

这个问题的解决方法有两种:

1:如果必须在onLoad的时候调用,那么在后面做一个异常检测, 如果screenWidth为0时候,赋一个默认值.

2:改在onReady的时候调用

li93
li933 楼6 年前

我也是碰到这个问题,官方有解决方案了么

pingzhu
pingzhu4 楼6 年前

你好,我也遇到同样的问题,请问下你最后是怎么解决了或者怎么规避了这个问题?

tanjun
tanjun5 楼4 年前

遇到同样的问题,官方有没有解决方案?