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



可能的重复:
如何以编程方式获取iOS的字母数字版字符串

是否有未来的证明正则是从用户代理获取以下智能手机OS的版本号?

android

(我找到了类似:/androids ([d。] )/)

ios

BlackBerry

任何建议都将不胜感激。

澄清:似乎问题是在问如何在Web应用中获取移动设备OS版本,可能是使用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;
}

如果您需要在Web应用中获取版本号,则最好的选择是使用设备用户代理并解析版本号。一种更强大的方法是查找WURFL数据库中的用户代理以获取设备特性和相应的OS。第一种方法更简单。

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

最新更新