资讯详情

移动端浏览器IOS13以上,陀螺仪调用注意事项

移动端iOS全景图更新到13版后,AR场景陀螺仪故障解决方案如下:

  1. 需要HTTPS协议
  2. 隐私设置开启运动传感器
  3. 监控事件代码调整,iOS13以后会新增window.DeviceOrientationEvent的API,orientationchange该事件用于处理水平和垂直屏幕转换,无用且可忽略。需要特别注意的是,其触发条件与音频和视频自动播放的安全协议相同,需要主动触发用户交互事件,如点击事件后。监控添加代码如下:
  // iOS 13     if ( window.DeviceOrientationEvent !== undefined && typeof window.DeviceOrientationEvent.requestPermission === 'function' ) { 
            window.DeviceOrientationEvent.requestPermission().then( function ( response ) { 
             if ( response == 'granted' ) { 
              window.addEventListener( 'orientationchange', onScreenOrientationChangeEvent, false );      window.addEventListener( 'deviceorientation', onDeviceOrientationChangeEvent, false );      }     } ).catch( function ( error ) { 
             console.error( 'Unable to use DeviceOrientation API:', error );     } );    } else { 
            window.addEventListener( 'orientationchange', onScreenOrientationChangeEvent, false );    window.addEventListener( 'deviceorientation', onDeviceOrientationChangeEvent, false );    } 

标签: 陀螺仪传感器api

锐单商城拥有海量元器件数据手册IC替代型号,打造 电子元器件IC百科大全!

锐单商城 - 一站式电子元器件采购平台