流星设备检测android或ios? [英] Meteor device detection android or ios?

查看:51
本文介绍了流星设备检测android或ios?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个为 ios 和 android 设备部署的流星应用程序,我希望某些代码仅在 ios 设备上运行,而不是在 android 上运行.我知道我可以使用诸如

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()

但是有什么可能的方法可以知道它是 android 还是 iOS 设备.

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

我使用meteor cordova创建了包.

I have created bundle using meteor cordova.

推荐答案

这里有一个全局帮助器,它应该可以解决检测 iOS 的问题:

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

另一个适用于 Android:

And another for Android:

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

在客户端 js 中的任何地方使用:

To use anywhere in client js:

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

当然,在 html 模板标记中使用:

And of course, to use in html template markup:

{{#if isIOS}}...{{/if}}
{{#if isAndroid}}...{{/if}}

这篇关于流星设备检测android或ios?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆