meteordevice-detection

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.


Solution

  • 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}}