第十四天(Environment Detection)

来源:互联网 发布:php throw exception 编辑:程序博客网 时间:2024/06/03 01:17

原文地址:http://docs-origin.sencha.com/touch/2.2.1/#!/guide/environment_package

 

Environment Detection

环境检测

Contents  目录

  1. Operating System    操作系统
  2. Browser    浏览器
  3. Features   特性

Commonly when building applications that target mobile devices, you need to know specific information about the environment your application is running on. Perhaps the browser type, the device name, or if specific functionality is available for use. The environment package in Sencha Touch gives you an API which allows you to find out all this information.

通常,当我们创建手机设备应用程序时,你需要知道知道应用运行所处环境的确切信息。包括浏览器类型,设备名称,亦或者某些特定功能是否可用。st中的环境包提供了一个api供你找出这些信息。

Operating System   操作系统

You can detect the operating system your application is running on using Ext.os.name. This returns one of the following values:

你可以使用Ext.os.name来检测你的应用所运行环境的操作系统。该属性返回下列值之一:

  • iOS
  • Android
  • webOS
  • BlackBerry
  • RIMTablet
  • MacOS
  • Windows
  • Linux
  • Bada
  • Other

You can also use the Ext.os.is singleton to check if the current OS matches a certain operating system. For example, if you wanted to check if the current OS is Android or Mac OS, you could use the following code:

你也可以使用单例的Ext.os.is来检测当前的操作系统是否与指定的操作系统相匹配。例如,如果你想检测当前操作系统是否是Android或者Mac OS,你可以使用下面的代码来判断:

if (Ext.os.is.Android) {    // ...}if (Ext.os.is.MacOS) {    // ...}

You can also use it to detect if the device is an iPhone, iPad, or iPod using Ext.os.is as follows:

你也可以使用Ext.os.is来判断当前设备是iPhone、iPad或者iPod,如下所示:

if (Ext.os.is.iPad) {    // ...}

The version of the OS can be also accessed using the following Ext.os.version call:

你可以调用Ext.os.version来访问当前操作系统的版本:

alert('You are running: ' + Ext.os.name + ', version ' + Ext.os.version.version);

Browser  浏览器

You can also find information about the browser you are running your application on by usingExt.browser.name. The list of available values are the following:

你也可以通过使用Ext.browser.name来找出应用所处环境的浏览器信息。可能的值如下列表所示:

  • Safari
  • Chrome
  • Opera
  • Dolfin
  • webOSBrowser
  • ChromeMobile
  • Firefox
  • IE
  • Other

You can also use Ext.browser.is to check if the current browser is one of the above values:

你也可以Ext.browser.is来检查当前浏览器是否是上述浏览器中的一种:

if (Ext.browser.is.Chrome) {    // ...}

The Ext.browser.is singleton also provides other useful information about the current browser that may be useful for your application:

单例的Ext.browser.is也提供了一些当前浏览器的其它有用信息,这些信息或许对你的应用有所帮助:

  • Ext.browser.userAgent - returns the current userAgent   返回当前的用户代理
  • Ext.browser.isSecure - returns true if the current page is using SSL   如果当前页使用ssl则返回true
  • Ext.browser.isStrict - returns true if the browser is in strict mode    如果浏览器处于严格模式则返回true
  • Ext.browser.engineName - returns the browser engine name (WebKit,Gecko, Presto, Trident and Other)    返回浏览器引擎的名字
  • Ext.browser.engineVersion - returns the version of the browser engine    返回浏览器引擎的版本

Features   特性

You can use the Ext.feature singleton to check if a certain browser feature exists. For example, if you want to check if the browser supports canvas, you check use the following code:

你也可以使用单例的Ext.feature来检查制定的浏览器特性是否存在。例如,如果你需要检测浏览器是否支持canvas,你可以使用下面的代码来进行检测:

if (Ext.feature.has.Canvas) {    // ...}

The available features are the following:

可用的特性如下:

  • 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