ios12.2系统原生摇一摇失效,ios12系统就没事
发布于 6 年前 作者 nshao 1687 次浏览 来自 问答
  • 当前 Bug 的表现(可附上截图)
  • 预期表现
  • 复现路径
  • 提供一个最简复现 Demo

if (window.DeviceMotionEvent) {

                            window.addEventListener(‘devicemotion’, deviceMotionHandler, false);

                        } else {

                            alert(‘您的手机不支持摇一摇’);

                        }

var SHAKE_THRESHOLD = 200;

            var last_update = 0;

            var initnum = 0;

            var x = y = z = last_x = last_y = last_z = 0;

            var num = 0;

deviceMotionHandler(eventData) {

                        var acceleration = eventData.accelerationIncludingGravity;

                        var curTime = new Date().getTime();

                        if ((curTime - last_update) > 100) {

                            var diffTime = curTime - last_update;

                            last_update = curTime;

                            x = acceleration.x;

                            y = acceleration.y;

                            z = acceleration.z;

                            var speed = Math.abs(x + y + z - last_x - last_y - last_z) / diffTime * 10000;

  

                            var x1 = Math.abs(x-last_x);

                            var y1 = Math.abs(y-last_y);

                            var z1 = Math.abs(z-last_z);

                            var max =0;

                            if(x1>y1){

                                if(x1>z1){

                                    max=x1;

                                }else{

                                    max=z1;

                                }

                            }else {

                                if(y1>z1){

                                    max=y1;

                                }else{

                                    max=z1;

                                }

                            }

                            if(max>40){

 

                                }

                            }else if(max<5&&isprint){

 

                            }

                            last_x = x;

                            last_y = y;

                            last_z = z;

                        }

                    }

2 回复

是小游戏的反馈?方便提供能复现问题的简单代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)么?

IOS12.2重力感应的问题,也限制了http地址的陀螺仪事件,必须https的地址才可以。


需要打开配置!设置->Safari浏览器->隐私与安全性->移动和方向访问

网上大神给出的答案:https://forum.cocos.com/t/h5-ios-12-2/76467/16

回到顶部