I have an meteor app that is deployed for both ios and android device and i want certain code to run on only ios device and not on android. I know that I can detect device using navigator.userAgent but this will only work if i have my app running on browser.
//This works if its a browser
navigator.userAgent.toLowerCase().indexOf("android") > -1;
But is there any possible way to detect device if i have created bundle for android using meteor cordova plugin so it works like a native app.
The easiest way to check your phone's model name and number is to use the phone itself. Go to the Settings or Options menu, scroll to the bottom of the list, and check 'About phone', 'About device' or similar. The device name and model number should be listed.
Device Detection is the process of capturing accurate real-time intelligence about the devices being used to access online information, including web and native apps. This Device Intelligence is used to identify where online content is performing best on any device, regardless of screen size.
To detect if the user is using a mobile device in JavaScript, we can use the userAgent property. This property is part of the navigator object and sent by the browser in HTTP headers. It contains information about the name, version, and platform of the browser.
No reason for plugins, just use window.
window.cordova.platformId
You can also get the version of the os.
Full output:
window.cordova.platformId
"android"
window.cordova.platformVersion
"7.0.0"
As Nijil Nair suggested use the Cordova Device Plugin . If you need help adding the plugin see Meteor Cordova . Once the plugin is properly installed you can use var devicePlatform = device.platform;
which will return one of the following based on the device:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With