我需要找到运行我的应用的设备ID。我正在使用角js和离子。有没有办法获取设备ID?
答案 0 :(得分:0)
选项1:使用AngularJS运行
// Calling the rootScope to handle the ondevice ready
angular.module('myApp').run(['$rootScope', function($rootScope) {
document.addEventListener('deviceready', function() {
$rootScope.$apply(function() {
$rootScope.myVariable = "variable value";
try {
$rootScope.uuid = device.uuid; //always use device object after deviceready.**
alert($rootScope.uuid);
//onapploginx(uuid);
} catch (e) {
alert(e);
}
// Register the event listener
document.addEventListener("backbutton", onBackKeyDown, false);
});
});
}]);
选项2:仅使用JS
在主体中定义onLoad
<body id="main_body" ng-app='myApp' ng-controller='DemoController' onload="onLoad()">
调用addEventListener以便设备准备就绪,然后调用onDeviceReady函数
function onLoad() {
console.log("i am onload");
document.addEventListener("deviceready", onDeviceReady, false);
}
// device APIs are available
//
function onDeviceReady() {
try {
var uuid = device.uuid; //always use device object after deviceready.**
alert("uuidx:",uuid);
} catch (e) {
alert(e);
}
}