add device detection logic
This commit is contained in:
parent
f2caf2758b
commit
894802bc81
26
src/utils/common/deviceDetection.ts
Normal file
26
src/utils/common/deviceDetection.ts
Normal 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;
|
Loading…
Reference in a new issue