-
-
Save bboydflo/70920e52f2f2b22bed6c1d77225188a4 to your computer and use it in GitHub Desktop.
Get iOS version via javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Semver { | |
constructor(major, minner, patch) { | |
this.major = major; | |
this.minner = minner; | |
this.patch = patch; | |
} | |
toString() { | |
return `${this.major}_${this.minner}_${this.patch}`; | |
} | |
} | |
function isIOS() { | |
const ua = navigator.userAgent; | |
return ua.indexOf("iPhone") > 0 || ua.indexOf("iPad") > 0 || ua.indexOf("iPhone") > 0; | |
} | |
function getIOSSemever() { | |
if (isIOS()) { | |
const extract = navigator.userAgent.match(/OS (\d+)_(\d+)_?(\d+)?/); | |
return new Semver( | |
parseInt(extract[1] || 0, 10), | |
parseInt(extract[2] || 0, 10), | |
parseInt(extract[3] || 0, 10) | |
); | |
} else { | |
return null; // or [0,0,0] | |
} | |
} | |
function isOverIOS9() { | |
const semver = getIOSSemever(); | |
console.log(`version: ${semver.toString()}`); | |
return semver.major >= 9; | |
} | |
// - exec | |
console.log(`overIOS9: ${isOverIOS9()}`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment