2012-06-01 65 views
8

我確定我只是忽略了這個問題,但我似乎無法找到如何檢查設備。
我想檢查設備是橫向模式的手機,平板電腦,縱向模式的平板電腦還是其他設備(計算機)。設備檢查sencha touch 2

什麼我是這樣的:

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

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

var x = Ext.platform; 

但平臺是不確定的(可能是因爲這是煎茶觸摸1的方式)。

有沒有人知道我訪問設備檢查的正確位置?

回答

18

Sencha Environment Detection答案通過簡單的手段提供了一個大範圍。

而不是Ext.os.is.Tablet,你可以通過Ext.os.deviceType將返回生活更輕鬆:

  • 電話
  • 平板
  • 桌面

注意:通過將「?deviceType =」添加到url中,該值也可以被欺騙。

http://localhost/mypage.html?deviceType=Tablet 

Ext.os.命名是單返回:

  • 的iOS
  • 的Android
  • 的webOS
  • 黑莓
  • RIMTablet
  • 的MacOS
  • 的Windows
  • 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 

方向Ext.device.Orientation和方向的變化:

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

方向是基於視口。我通常添加一個更可靠的監聽器:

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... 
    } 
4

使用Ext.env.OS'sis()方法。

請注意,只有主要成分,版本簡化價值 通過直接屬性檢驗可用。支持的值是:iOS上, 的iPad,iPhone,iPod的,Android,WebOS的,黑莓,巴達,MacOS的,Windows中, Linux和其他

if (Ext.os.is('Android')) { ... } 
if (Ext.os.is.Android2) { ... } // Equivalent to (Ext.os.is.Android && Ext.os.version.equals(2)) 

if (Ext.os.is.iOS32) { ... } // Equivalent to (Ext.os.is.iOS && Ext.os.version.equals(3.2)) 

另外,您還可以使用PhoneGap Device API

+0

我確實看到過這種方式,但問題在於我還想指定設備是移動設備還是平板電腦。 Android例如可以在平板電腦或移動設備上運行。 –

2

我找到了答案:

什麼似乎是這樣的Ext.os.is.(平板電腦/電話或其他)是真實的或未定義的。如果不是這種情況,它將是未定義的。 I.a.在平板電腦上時爲Ext.os.is.Tablet,在未定義時爲undefined。

所以這就是我一直在尋找

if(Ext.os.is.Tablet){ 
     this._bIsTablet = true; 
    }else if(Ext.os.is.Phone){ 
     this._bIsPhone = true; 
    }else{ 
     this._bIsOther = true; 
    }