Meteor device detection android or ios?
Asked Answered
S

1

9

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.

Suburban answered 18/8, 2015 at 15:30 Comment(0)
S
16

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}}
Sirkin answered 18/8, 2015 at 15:52 Comment(5)
u have used indexof for android and match for ios does that makes any differnceSuburban
Not really - Android is simpler since it only comes in one flavor. iOS comes in 3.Sirkin
this only works for broswer but what if i have created bundle using meteor cordovaSuburban
Sorry to necro, but how would one do this within react?Abundance
This SO answer should help you with React. Just define the functions and export them, then require them in your jsx.Sirkin

© 2022 - 2024 — McMap. All rights reserved.