function deviceMoved(){
moved = true;
bulb.stop();
playing = false;
}在我的sketch.js (p5.js)上,这个事件不是在手机上触发的,deviceShaken()也不是。谷歌Chrome版本在80左右左右,我的手机是华为的P20 Lite。我正在使用http,但是https也没有产生任何结果。有人知道为什么或如何解决这个问题吗?
发布于 2020-03-18 17:16:08
解决了!这是一个相当棘手的问题。在Android和iOS中,您都需要启用https。在iOS 13+中,您还需要请求权限(并且需要在用户交互中完成)。
就像这样:
if (typeof DeviceMotionEvent.requestPermission === 'function' &&
typeof DeviceOrientationEvent.requestPermission === 'function'
) {
// iOS 13+
askButton = createButton('Permission');
askButton.size(windowWidth*6/8, windowHeight/8);
askButton.position(windowWidth/2 - drumButton.width/2, windowHeight/2);
askButton.mousePressed(() => {
DeviceMotionEvent.requestPermission()
.then(response => {
if (response === 'granted') {
window.addEventListener('devicemotion', deviceMotionHandler, true);
}
});
DeviceOrientationEvent.requestPermission()
.then(response => {
if (response === 'granted') {
window.addEventListener('deviceorientation', deviceTurnedHandler, true)
}
})
.catch(console.error)https://stackoverflow.com/questions/60663692
复制相似问题