一.引入mobile-detect.min.js
onLaunch: function() {
console.log('App Launch');
var script = document.createElement('script');
script.src="http://xxxxxxx.js"
document.head.appendChild(script);
},
二.获取当前设备名称
getMobile() {
//判断数组中是否包含某字符串
Array.prototype.contains = function(needle) {
for (i in this) {
if (this[i].indexOf(needle) > 0) return i;
}
return -1;
};
var deviceType = navigator.userAgent; //获取userAgent信息
var md = new MobileDetect(deviceType); //初始化mobile-detect
var os = md.os(); //获取系统
//系统的版本号
var version = '';
if (os == 'iOS') {
//ios系统的处理
version = md.version('iPhone');
os = md.os();
this.safeForm.model = md.mobile(); //设备名称
} else if (os == 'AndroidOS') {
//Android系统的处理
os = md.os();
version = md.version('Android');
var sss = deviceType.split(';');
var i = sss.contains('Build/');
if (i > -1) {
this.safeForm.model = sss[i].substring(0, sss[i].indexOf('Build/'));
}
}
},