Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meteor device detection android or ios?

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 meteor device-detection package like

Meteor.Device.isPhone()

But is there any possible way can know if its an android or iOS device.

EDIT: I have created bundle using meteor cordova.

like image 287
Nakib Avatar asked Aug 18 '15 15:08

Nakib


1 Answers

Here's a global helper that should do the trick as far as detecting iOS:

Template.registerHelper('isIOS',() => {
  return ( navigator.userAgent.match(/(iPad|iPhone|iPod)/g) ? true : false );
});

And another for Android:

Template.registerHelper('isAndroid',() => {
  return navigator.userAgent.toLowerCase().indexOf("android") > -1;
});

To use anywhere in client js:

Blaze._globalHelpers.isIOS()
Blaze._globalHelpers.isAndroid()

And of course, to use in html template markup:

{{#if isIOS}}...{{/if}}
{{#if isAndroid}}...{{/if}}
like image 117
Michel Floyd Avatar answered Oct 17 '22 07:10

Michel Floyd