Device ionic-native


#1

I’m trying to add Device plugin to my app, but with no success. I’ve already added Geolocation and it works fine. Do I need some typings install ?

this is the plugin http://ionicframework.com/docs/v2/native/Device/


constructor(nav: NavController) {
    this.nav = nav;
    let info = Device.getDevice();
  }

I’m receiving this error:

app.bundle.js:34063 ORIGINAL EXCEPTION: TypeError: ionic_native_1.Device.getDevice is not a functionBrowserDomAdapter.logError @ app.bundle.js:34063ExceptionHandler.call @ app.bundle.js:7831(anonymous function) @ app.bundle.js:17002NgZone._notifyOnError @ app.bundle.js:17661collection_1.StringMapWrapper.merge.onError @ app.bundle.js:17556Zone.run @ app.bundle.js:2262(anonymous function) @ app.bundle.js:17574zoneBoundFn @ app.bundle.js:2235lib$es6$promise$$internal$$tryCatch @ app.bundle.js:1483lib$es6$promise$$internal$$invokeCallback @ app.bundle.js:1495lib$es6$promise$$internal$$publish @ app.bundle.js:1466(anonymous function) @ app.bundle.js:1138microtask @ app.bundle.js:17614Zone.run @ app.bundle.js:2258(anonymous function) @ app.bundle.js:17574zoneBoundFn @ app.bundle.js:2235lib$es6$promise$asap$$flush @ app.bundle.js:1277
app.bundle.js:34063 ORIGINAL STACKTRACE:BrowserDomAdapter.logError @ app.bundle.js:34063ExceptionHandler.call @ app.bundle.js:7834(anonymous function) @ app.bundle.js:17002NgZone._notifyOnError @ app.bundle.js:17661collection_1.StringMapWrapper.merge.onError @ app.bundle.js:17556Zone.run @ app.bundle.js:2262(anonymous function) @ app.bundle.js:17574zoneBoundFn @ app.bundle.js:2235lib$es6$promise$$internal$$tryCatch @ app.bundle.js:1483lib$es6$promise$$internal$$invokeCallback @ app.bundle.js:1495lib$es6$promise$$internal$$publish @ app.bundle.js:1466(anonymous function) @ app.bundle.js:1138microtask @ app.bundle.js:17614Zone.run @ app.bundle.js:2258(anonymous function) @ app.bundle.js:17574zoneBoundFn @ app.bundle.js:2235lib$es6$promise$asap$$flush @ app.bundle.js:1277
app.bundle.js:34063 TypeError: ionic_native_1.Device.getDevice is not a function
    at new Queues (app.bundle.js:63090)
    at app.bundle.js:8085
    at Injector._instantiate (app.bundle.js:6643)
    at Injector._instantiateProvider (app.bundle.js:6597)
    at Injector._new (app.bundle.js:6586)
    at InjectorInlineStrategy.instantiateProvider (app.bundle.js:6086)
    at ElementDirectiveInlineStrategy.init (app.bundle.js:18972)
    at new AppElement (app.bundle.js:18649)
    at HostViewFactory.viewFactory_HostQueues0 [as viewFactory] (viewFactory_HostQueues:122)
    at AppViewManager_.createHostViewInContainer (app.bundle.js:20039)

#2

Device.device.model;


#3

Device.device.model; or Device.device.uuid; returns undefined when run in my iphone (ionic run ios)

Why the method described in ionic-native is not working?

Thanks


#4

Use it like @xr0master described, the docs are out of date. I’ve updated the example and opened an issue for the property documentation not generating properly: https://github.com/driftyco/ionic-native/issues/77.

Also you can’t use any plugins before platform ready, this is also a documentation issue that will be resolved soon (a how-to page for using ionic-native plugins).

constructor(platform: Platform) {
  platform.ready().then(() => {
    console.log('Now you can use plugins');
    console.log('UUID is: ' + Device.device.uuid);
  }
}

Sorry for the rough experience, the docs for Ionic Native are still a WIP! You can fix any mistakes you find by clicking the ‘Improve this doc’ button at the top of any of the Ionic Native doc pages which will let you edit and PR the source directly :slight_smile:


#5

Device.device.uuid works! thanks man, anyway is not much clear how to use ionic-native components in general. Maybe a section inside [tutorial] (http://ionicframework.com/docs/v2/getting-started/tutorial/) will be great for newbies :slight_smile: