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

后端 未结 6 2131
攒了一身酷
攒了一身酷 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:05

    I did expand the implementation a little to make use of some more default browser features on iPad OS vs Mac OS Catalina. According to my tests on diverse iPads and all late iOS Devices this works well.

    var isIPadOs = window.AuthenticatorAssertionResponse === undefined
            && window.AuthenticatorAttestationResponse === undefined
            && window.AuthenticatorResponse === undefined
            && window.Credential === undefined
            && window.CredentialsContainer === undefined
            && window.DeviceMotionEvent !== undefined
            && window.DeviceOrientationEvent !== undefined
            && navigator.maxTouchPoints === 5
            && navigator.plugins.length === 0
            && navigator.platform !== "iPhone";
    

    Gist: https://gist.github.com/braandl/f7965f62a5fecc379476d2c055838e36

提交回复
热议问题