LoginSignup
10
3

More than 3 years have passed since last update.

ios13 -> DeviceMotionEvent DeviceOrientationEvent requestPermission になるのか

Last updated at Posted at 2019-09-20

safari で iOS12.2では 設定からの
68747470733a2f2f74796f2e73616d75726169776f726b732e6f72672f696d616765732f494d475f303939342e6a7067.jpg

でしたが、また変わった🙁。。そしてiOS13ではJS側で許可したクリックイベント作るんですね。
出典:iOS 13でデバイスの動きと方向の許可を要求する方法

自作のWebAppで実装して動作確認をしたのでメモです
DeviceOrientationEvent ←→ DeviceMotionEvent
window.addEventListener('deviceorientation' ←→ window.addEventListener('devicemotion'

bunki.js
    if (typeof DeviceOrientationEvent.requestPermission === 'function') {
      // iOS 13+
      popupOpen("requestPermissionPopup");
    } else {
      // non iOS 13+
      window.addEventListener("deviceorientation", 今までのイベント);
    }

で、13+かを判定して、
なにかUIでクリックイベントを設定して、

hoge.html
<button onclick="requestPermission()">このエリアを押して モーションの利用を許可してください (iOS 13+) </button>

13+ で許可されたイベントリスナで

bunki.js
  // 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 になった模様。

10
3
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
3