How to detect iPad and iPad OS version in iOS 13 and Up?

后端 未结 6 2140
攒了一身酷
攒了一身酷 2020-12-06 09:32

I can detect iOS 13 on iPhone but in iPad OS 13 navigator.platform comes as MacIntel. So it is not possible to get iPad identified using below code, but it work

6条回答
  •  隐瞒了意图╮
    2020-12-06 10:15

    I was able to get iPad detection working by checking for navigator.maxTouchPoints as well as navigator.platform. It's not perfect (as discussed in the comments below) but it's the best solution I've come across so far so I wanted to share.

    const iPad = (userAgent.match(/(iPad)/) /* iOS pre 13 */ || 
      (navigator.platform === 'MacIntel' && navigator.maxTouchPoints > 1) /* iPad OS 13 */);
    

提交回复
热议问题