通过以下方式安装了 cordova 设备插件:
sudo cordova plugin add org.apache.cordova.device
然后下载 ngCordova 并将 ng-cordova.min.js 包含在 js 文件夹中,也包含在 index.html 中
接下来我做的是注入(inject) ngCordova,如下所示
angular.module('starter', ['ionic', 'starter.controllers','ngCordova'])
然后包含在controller中如下
angular.module('starter.controllers', [])
.controller('AppCtrl', function($scope, $ionicModal, $timeout, $ionicPlatform,$cordovaDevice)
but still getting the following errors
ReferenceError: device is not defined
at Object.getUUID (http://localhost:8100/js/ng-cordova.min.js:1:14929)
at new <anonymous> (http://localhost:8100/js/controllers.js:27:26)
at invoke (http://localhost:8100/lib/ionic/js/ionic.bundle.js:11591:17)
at Object.instantiate (http://localhost:8100/lib/ionic/js/ionic.bundle.js:11602:23)
at http://localhost:8100/lib/ionic/js/ionic.bundle.js:14906:28
at updateView (http://localhost:8100/lib/ionic/js/ionic.bundle.js:42986:30)
at eventHook (http://localhost:8100/lib/ionic/js/ionic.bundle.js:42933:17)
at Scope.$broadcast (http://localhost:8100/lib/ionic/js/ionic.bundle.js:20605:28)
at $state.transition.resolved.then.$state.transition (http://localhost:8100/lib/ionic/js/ionic.bundle.js:34122:22)
at wrappedCallback (http://localhost:8100/lib/ionic/js/ionic.bundle.js:19197:81)
你现在能告诉我哪里出了问题吗?
如果有另一种读取设备 UUID 的方法,请告诉我它的方向。
最佳答案
是的,还有另一种方法。 您只是不需要 ngCordova 即可。
当您添加插件 cordova plugin add org.apache.cordova.device
时,它会加载到您的应用程序中,因此您需要的信息位于 window.device
。
如果你想在代码的任何地方获取设备uuid,你只需要调用window.device.uuid
。
如果您希望应用程序一启动,请使用:
ionic.Platform.ready(function(){
console.log( window.device.uuid );
});
关于android - 如何在 ionic 框架中获取设备 UUID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27466813/