How to get the device UUID in ionic framework

2019-02-04 13:34发布

installed cordova device plugin by :

sudo cordova plugin add org.apache.cordova.device

then downloaded ngCordova and included ng-cordova.min.js in to js folder and also included in index.html

next what i did is injected ngCordova as follows

angular.module('starter', ['ionic', 'starter.controllers','ngCordova'])

then included in controller as follows

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)

Can you now tell me what went wrong?

If is there another way to read the Device UUID show me the direction to it.

9条回答
仙女界的扛把子
2楼-- · 2019-02-04 14:13

Use ngCordova and cordova Device plugin:

cordova plugin add org.apache.cordova.device

module.controller('MyCtrl', function($scope, $cordovaDevice) {
  var uuid = $cordovaDevice.getUUID();
});
查看更多
3楼-- · 2019-02-04 14:19

wow found out what wrong i was doing... through this question. http://forum.ionicframework.com/t/problem-to-use-ngcordova-device-is-not-defined/11979

when we test on other device which has other platform than cordova supports this happens. this was a useful discovery for me.

查看更多
男人必须洒脱
4楼-- · 2019-02-04 14:21

Have been struggling with this for hours today, install the cordova device plugin with:

cordova plugin add cordova-plugin-device

make sure you also reference the plugin in your config.xml:

<plugin name="cordova-plugin-device" source="npm" spec="~1.1.1" />

查看更多
登录 后发表回答