智能手机操作系统的版本号

时间:2012-10-23 03:57:04

标签: javascript android ios regex blackberry

  

可能重复:
  How to programmatically get iOS’s alphanumeric version string

是否有任何未来的证明正则表达式可以从用户代理处获取以下智能手机操作系统的版本号?

的Android

(我发现了类似:/ Androids+([d。] +)/)

的iOS

黑莓

任何建议都会非常感激。

澄清:似乎问题是如何在网络应用程序中获取移动设备操作系统版本,可能使用JS。

更新:

在我得到这个问题之后,我想要至少提供我想出的解决方案:

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;
}

1 个答案:

答案 0 :(得分:1)

如果您需要在网络应用中获取版本号,最好的办法是使用设备用户代理并解析版本号。更健壮的方法是在WURFL database中查找用户代理以获得设备特征和相应的OS。第一种方法更简单。

如果您使用的是应用程序,大多数操作系统SDK都会提供API来识别设备上运行的操作系统的版本