Meteor device detection android or ios?

☆樱花仙子☆ 提交于 2019-12-08 19:23:05

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/32076642/meteor-device-detection-android-or-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!