我创建了一个新的类星体项目,添加了cordova,并尝试了一下。
一切正常,我可以在我的手机上部署应用程序并在模拟器中运行它。
现在,我需要获取一些设备信息,我想使用cordova-plugin-device来实现。插件正在加载,就像我安装的每个插件一样。我可以在iOS xCode仿真器的开发人员窗口(safari)中看到它。
现在,我尝试获取设备信息,就像文档中描述的那样:
https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-device/index.html
类似于App.vue中的内容:
mounted: function () {
document.addEventListener('deviceready', this.onDeviceReady, false)
},
methods: {
onDeviceReady: function () {
console.log('cordova', cordova)
console.log('device', device)
}
...但控制台中始终会出现以下错误:
错误‘device’没有定义-undef
我该如何解决这个问题呢?我已经删除了平台,并重新添加了它。
我没有想法,在互联网上找不到任何相关的东西。
提前感谢干杯巴斯蒂
发布于 2019-07-31 21:22:26
在类星体社区的帮助下,我已经可以解决我的问题了。
神奇的字眼是:window.device。
发布于 2019-08-01 14:39:18
尝尝这个
var Type = (navigator.userAgent.match(/iPad/i)) == "iPad" ? "iPad" : (navigator.userAgent.match(/iPhone/i)) == "iPhone" ? "iPhone" : (navigator.userAgent.match(/Android/i)) == "Android" ? "Android" : (navigator.userAgent.match(/BlackBerry/i)) == "BlackBerry" ? "BlackBerry" : "null";
alert(Type);https://stackoverflow.com/questions/57290695
复制相似问题