Detect iPhone 3G or 3GS (and iPod touch 2G vs iPod touch 3G) in JavaScript

后端 未结 3 1709
醉梦人生
醉梦人生 2021-02-07 20:16

Does anyone know a way to detect the older set of devices:

  • iPod touch 1G
  • iPhone 2G
  • iPhone 3G
  • iPod touch 2G

From the newer

3条回答
  •  迷失自我
    2021-02-07 20:55

    Little Benchmark that detects older models. The Benchmark takes 5-30ms so no real problem.

    function runBenchmark(){
        var time,
        init = new Date(),
        iterations = 5000;
        while (iterations--) {
            Math.sqrt(iterations*Math.random());
        }
        time = new Date - init;
        return time;
    }
    
    function detectIphoneSpeed () {
        if (runBenchmark()<15) {
            return "3gs";
        } else {
            return "3g";
        }
    }
    var iphoneSpeed = detectIphoneSpeed();
    

提交回复
热议问题