2012-10-23 67 views
-2

可能重複號:
How to programmatically get iOS’s alphanumeric version string版本智能手機操作系統的

是否有面向未來的正則表達式來從用戶代理下面的智能手機操作系統的版本號?

的Android

(我發現是這樣的:/Androids+([d.]+)/)

的iOS

黑莓

任何建議會非常感謝。

說明:似乎問題是問如何獲取Web應用程序中的移動設備操作系統版本,可能使用JS。

UPDATE:

後,我得到了相當撞壞問這個問題,我想至少提供我想出了一個解決方案:

supportedDevice: function() { 
    var supportedDevice = false; 
    var userAgent = window.navigator.userAgent; 

    // check for supported Android device 
    if (/Android/.test(userAgent)) { 
     var a_index = Number(userAgent.indexOf('Android')) + 8; 
     var a_version = +userAgent.substring(a_index, a_index+1); 
     if (a_version >= 3) { 
      supportedDevice = true; 
      console.log('Android device supported!') 
     } 

    } 
    // check for iOS supported devices 
    else if (/iPhone/.test(userAgent)) { 
     var i_index = Number(userAgent.indexOf('iPhone OS')) + 10; 
     var i_version = +userAgent.substring(i_index, i_index+1); 
     if (i_version >= 6) { 
      supportedDevice = true; 
      console.log('iPhone device supported!') 
     } 
    } 
    // check for iOS supported devices 
    else if (/BlackBerry/.test(userAgent)) { 
     var b_index = Number(userAgent.indexOf('Version/')) + 8; 
     var b_version = +userAgent.substring(b_index, b_index+1); 
     if (b_version >= 6) { 
      supportedDevice = true; 
      console.log('BB device supported!') 
     } 
    } 
    return supportedDevice; 
} 
+4

你通常不會只用一個正則表達式來獲得一個版本號;您可能會使用特定於平臺的方法來獲取該號碼。 – nneonneo

+0

如何使用剛剛使用HTML5,CSS3和JavaScript等開放標準開發的移動Web應用程序使用特定於平臺的方法? – bardu

+0

提供從編程語言結尾看到的輸入。例如:IOS 5.2.1等, – pogo

回答

1

如果你需要獲得一個Web應用程序的版本號,您最好的選擇是使用設備用戶代理並解析出版本號。更可靠的方法是查找WURFL database中的用戶代理以獲取設備特性和相應的操作系統。第一種方法更簡單。

如果您正在使用的應用程序,大多數操作系統的SDK提供API來標識設備上運行的操作系統的版本

相關問題