Detect if device is iOS

前端 未结 17 1802
一整个雨季
一整个雨季 2020-11-22 01:39

I\'m wondering if it\'s possible to detect whether a browser is running on iOS, similar to how you can feature detect with Modernizr (although this is obviously device detec

17条回答
  •  离开以前
    2020-11-22 02:22

    Detecting iOS (both <12, and 13+)

    Community wiki, as edit queue says it is full and all other answers are currently outdated or incomplete.

    const iOS_1to12 = /iPad|iPhone|iPod/.test(navigator.platform);
    
    const iOS13_iPad = (navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1));
    
    const iOS1to12quirk = function() {
      var audio = new Audio(); // temporary Audio object
      audio.volume = 0.5; // has no effect on iOS <= 12
      return audio.volume === 1;
    };
    
    const isIOS = !window.MSStream && (iOS_1to12 || iOS13_iPad || iOS1to12quirk());
    

提交回复
热议问题