移动端:js判断苹果ios各类机型

移动端:js判断苹果ios各类机型,第1张

  最近在做一个移动端的项目,项目出现的一大堆兼容问题是在让我头疼,其中就包括获取 当前使用的 ios 的 机型。逛了很多圈博客,很多是用了组件实现的,也不知道是我方法没用对还是怎么回事,我用的组件只能获取到安卓手机的机型,最后只能采用比较笨的方法了,根据苹果手机的像素比和分辨率进行区分,代码如下:

/* 
  设备的像素比和设备分辨率表如下:
  iPhone 3GS  3.5寸 => 320x480 => 1
  iPhone 4/4s  3.5寸 => 320x480 => 2
  iPhone 5/5s/5c  4.0寸 =>  320x568 => 2
  iPhone 6   4.7寸 => 375x667 => 2
  iPhone 6Plus  5.5寸 => 414x736 => 3
  iPhone 6s  4.7寸 => 375x667 => 2
  iPhone 6sPlus  5.5寸 => 414x736 => 3
  iPhone 7  4.7寸 => 375x667 => 2
  iPhone 7Plus  5.5寸 => 414x736 => 3
  iPhone 8  4.7寸 => 375x667 => 2
  iPhone 8Plus5  5.5寸 => 414x736 => 3
  iPhone X  5.8寸 => 375x812 => 3
  iPhone XS  5.8寸 => 375x812 => 3
  iPhone XS Max6.5寸 => 414x896 => 3
  iPhone XR  6.1寸 => 414x896 => 2
*/
let iPhone4_4s = window.devicePixelRatio && window.devicePixelRatio === 2 && window.screen.width === 320 && window.screen.height === 480
let iPhone5_5s_5c = window.devicePixelRatio && window.devicePixelRatio === 2 && window.screen.width === 320 && window.screen.height === 568
let iPhone6_6s_7_8 = window.devicePixelRatio && window.devicePixelRatio === 2 && window.screen.width === 375 && window.screen.height === 667
let iPhone6P_6sP_7P_8P = window.devicePixelRatio && window.devicePixelRatio === 3 && window.screen.width === 414 && window.screen.height === 736


   接下来的机型大家可以根据上面的注释写下去,这里我只判断到了iphone8

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/990487.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-21
下一篇 2022-05-21

发表评论

登录后才能评论

评论列表(0条)

保存