设备检查sencha touch 2

Ric*_*ing 8 sencha-touch-2

我确定我只是忽略了这个问题,但我似乎无法找到如何检查设备.
我想检查设备是手机,横向模式平板电脑,纵向模式平板电脑还是其他设备(计算机).

我有的是这个:

if (Ext.platform.isPhone) {
    console.log("phone");
}

if (Ext.platform.isTablet) {
    console.log("tablet");
}

var x = Ext.platform;
Run Code Online (Sandbox Code Playgroud)

但是平台是未定义的(可能是因为这是Sencha Touch 1的方式).

有谁知道我访问设备检查的正确位置?

gre*_*ott 18

Sencha环境检测通过简单的方法提供大范围的光谱.

而不是Ext.os.is.Tablet,您可以通过Ext.os.deviceType使生活更轻松,它将返回:

  • 电话
  • 片剂
  • 桌面

注意:也可以通过在网址中添加"?deviceType ="来捏造此值.

http://localhost/mypage.html?deviceType=Tablet
Run Code Online (Sandbox Code Playgroud)

Ext.os.name是返回的单例:

  • iOS版
  • Android的
  • webOS的
  • 黑莓
  • RIMTablet
  • 苹果系统
  • 视窗
  • Linux的
  • 巴达
  • 其他

通过Ext.browser.name可以获得通常的浏览器检测功能.

我最近才遇到的东西,我喜欢的是功能检测 - 允许类似于Modernizr/YepNope的编码基于设备的能力.Ext.feature提供:

  • Ext.feature.has.Audio
  • Ext.feature.has.Canvas
  • Ext.feature.has.ClassList
  • Ext.feature.has.CreateContextualFragment
  • Ext.feature.has.Css3dTransforms
  • Ext.feature.has.CssAnimations
  • Ext.feature.has.CssTransforms
  • Ext.feature.has.CssTransitions
  • Ext.feature.has.DeviceMotion
  • Ext.feature.has.Geolocation
  • Ext.feature.has.History
  • Ext.feature.has.Orientation
  • Ext.feature.has.OrientationChange
  • Ext.feature.has.Range
  • Ext.feature.has.SqlDatabase
  • Ext.feature.has.Svg
  • Ext.feature.has.Touch
  • Ext.feature.has.Video
  • Ext.feature.has.Vml
  • Ext.feature.has.WebSockets

要在iOS上检测全屏/应用/主屏幕浏览器模式:

window.navigator.standalone == true
Run Code Online (Sandbox Code Playgroud)

Orientation Ext.device.Orientation和orientation changes:

Ext.device.Orientation.on({
    scope: this,
    orientationchange: function(e) {
        console.log('Alpha: ', e.alpha);
        console.log('Beta: ', e.beta);
        console.log('Gamma: ', e.gamma);
    }
});
Run Code Online (Sandbox Code Playgroud)

方向基于Viewport.我通常添加一个更可靠的监听器:

   onOrientationChange: function(viewport, orientation, width, height) {
        // test trigger and values
        console.log('o:' + orientation + ' w:' + width + ' h:' + height);

        if (width > height) {
            orientation = 'landscape';
        } else {
            orientation = 'portrait';
        }
        // add handlers here...
    }
Run Code Online (Sandbox Code Playgroud)