简体   繁体   English

流星:如何检测设备型号和操作系统版本?

[英]Meteor: How to detect device model & OS version?

I want to get user's the device model, OS version and screen resolution from my Cordova clients. 我想从我的Cordova客户端获取用户的设备型号,操作系统版本和屏幕分辨率。 Kadira does this beautifully. Kadira做得很漂亮。

在此处输入图片说明

How do I do this in my app? 如何在我的应用程序中执行此操作? Is there an existing package? 是否有现有的软件包?

Thanks 谢谢

An almost trivial answer without any Cordova plugins or Meteor packages: 几乎没有任何Cordova插件或Meteor软件包的简单答案:

var device_info = window.navigator.userAgent;
var display_size = screen.width + 'x' + screen.height;

device_info looks something like "Mozilla/5.0 (Linux; Android 5.1.1; Nexus 5 Build/LMY48M; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/50.0.2661.86 Mobile Safari/537.36", device_info看起来类似于“ Mozilla / 5.0(Linux; Android 5.1.1; Nexus 5 Build / LMY48M; wv)AppleWebKit / 537.36(KHTML,如Gecko)版本/4.0 Chrome / 50.0.2661.86 Mobile Safari / 537.36”,

Quick and dirty, but all the information is in there and there are no Cordova native plugins to go wrong. 快速又肮脏,但是所有信息都在那里,并且没有Cordova本机插件出错。

I think you're looking for this plugin: https://www.npmjs.com/package/cordova-plugin-device 我认为您正在寻找此插件: https : //www.npmjs.com/package/cordova-plugin-device

/////// EDIT ////////////// ///////编辑///////////////

Well, I don't use meteor, but I can drop you a jquery sniplet: 好吧,我不使用流星,但是我可以给你一个jQuery片段:

jQuery(document).ready(function($) {

    $(document).on('deviceready', function() {

        $('#device-platform').html(device.platform); 
        $('#device-version').html(device.version);
        $('#device-cordova').html(device.cordova);
        $('#device-model').html(device.model);
        $('#device-uuid').html(device.uuid);

    });

});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM