Решено! Это было довольно сложно. И в 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)