More than 5 years have passed since last update.
ios13 -> DeviceMotionEvent DeviceOrientationEvent requestPermission になるのか
safari で iOS12.2では 設定からの
👁 68747470733a2f2f74796f2e73616d75726169776f726b732e6f72672f696d616765732f494d475f303939342e6a7067.jpg
でしたが、また変わった🙁。。そしてiOS13ではJS側で許可したクリックイベント作るんですね。
出典:iOS 13でデバイスの動きと方向の許可を要求する方法
自作のWebAppで実装して動作確認をしたのでメモです
DeviceOrientationEvent ←→ DeviceMotionEvent
window.addEventListener('deviceorientation' ←→ window.addEventListener('devicemotion'
if (typeof DeviceOrientationEvent.requestPermission === 'function') {
// iOS 13+
popupOpen("requestPermissionPopup");
} else {
// non iOS 13+
window.addEventListener("deviceorientation", 今までのイベント);
}
で、13+かを判定して、
なにかUIでクリックイベントを設定して、
<button onclick="requestPermission()">このエリアを押して モーションの利用を許可してください (iOS 13+) </button>
13+ で許可されたイベントリスナで
// for ios13
requestPermission = ()=> {
DeviceOrientationEvent.requestPermission().then(response => {
if (response === 'granted') {
window.addEventListener("deviceorientation", ios13で許可したイベント);
}
}).catch(console.error);
};
で自分のWebAppでdeviceorientation動くことは確認しました。
許可の1タップがまた増えるのがなんだかなぁ。個人の設定で永続性はできないんですかねぇ。IEの記憶再び。。。🙁
chromeは今の所何もせず動いています。:追記 v78 ios requestPermission になった模様。
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme
