add device detection logic

This commit is contained in:
Abhinav 2022-01-19 10:31:36 +05:30
parent f2caf2758b
commit 894802bc81

View file

@ -0,0 +1,26 @@
const GetDeviceOS = () => {
let userAgent = '';
if (
typeof window !== 'undefined' &&
typeof window.navigator !== 'undefined'
) {
userAgent = navigator.userAgent || navigator.vendor || window.opera;
}
// Windows Phone must come first because its UA also contains "Android"
if (/windows phone/i.test(userAgent)) {
return 'wp';
}
if (/android/i.test(userAgent)) {
return 'android';
}
// iOS detection from: http://stackoverflow.com/a/9039885/177710
if (/iPad|iPhone|iPod/.test(userAgent) && !window.MSStream) {
return 'ios';
}
return 'unknown';
};
export default GetDeviceOS;