Last active
July 8, 2022 07:25
-
-
Save AvocadoVenom/26137e4c9af37f6e832602ae084956ae to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| enum MobileOS { | |
| Android = 'android', | |
| iOS = 'ios', | |
| Unknown = 'unknown', | |
| WindowsPhone = 'Windows Phone' | |
| } | |
| /** | |
| * https://stackoverflow.com/a/21742107 | |
| * Determine the mobile operating system. | |
| * | |
| * @returns {MobileOS} | |
| */ | |
| const getMobileOS = (): MobileOS | undefined => { | |
| if (isMobileDevice()) { | |
| // Windows Phone must come first because its UA also contains "Android" | |
| if (/windows phone/i.test(userAgent)) return MobileOS.WindowsPhone | |
| else if (/android/i.test(userAgent)) return MobileOS.Android | |
| // iOS detection from: http://stackoverflow.com/a/9039885/177710 | |
| if (/iPad|iPhone|iPod/.test(userAgent) && !window.MSStream) return MobileOS.iOS | |
| return MobileOS.Unknown | |
| } else return undefined | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment