2015-08-18 64 views
4

我有一個爲iOS和Android設備部署的流星應用程序,我希望某些代碼只在iOS設備上運行,而不是在Android上運行。我知道我可以使用navigator.userAgent檢測設備,但只有當我的應用程序在瀏覽器上運行時才能使用。設備檢測如果是android?

//這個作品,如果它是一個瀏覽器

navigator.userAgent.toLowerCase().indexOf("android") > -1; 

但有任何可能的方式來檢測設備,如果我有使用流星科爾多瓦插件創建包爲Android所以它就像一個原生應用。

+0

您是否嘗試過設備API?您可以檢查是否(device.platform =='Android') –

+0

可能重複[流星設備檢測android或ios?](http://stackoverflow.com/questions/32076642/meteor-device-detection-android-or- ios) –

回答

7

由於Nijil Nair建議使用Cordova Device Plugin。如果您需要添加插件的幫助,請參閱Meteor Cordova。一旦插件被正確安裝,你可以使用var devicePlatform = device.platform;將返回一個基於設備上的以下內容:

  • 「Android」的
  • 「黑莓」
  • 「iOS版」
  • 「WinCE的」
+1

流星科爾多瓦鏈接已轉移到:https://guide.meteor.com/mobile.html#introduction – ninjaPixel

+0

不是所有版本的Windows都返回'WinCE',請檢查[this](https://cordova.apache.org /docs/en/latest/reference/cordova-plugin-device/index.html#deviceplatform)瞭解更多信息。 – Taurus