Ionic-native: 2.2.10 broke Device plugin (and probably other plugins?)

Created on 6 Dec 2016  路  18Comments  路  Source: ionic-team/ionic-native

After updating to 2.2.10, when accessing Device plugin, it is undefined.

I'm calling it when platform is ready. Other plugins I'm using seems to work (AppVersion, SocialSharing)

Snippets from my code;

import { GoogleAnalytics, Device, AppVersion, SocialSharing } from 'ionic-native';

... 

    public onSupport(): void {
        this._platform.ready().then(() => {
            SocialSharing.canShareViaEmail()
                .then(() => {
                    const subject = this._getLocalizedSubject();
                    const body =
                        this._getLocalizedBody() +
                        `\n\n\n\n\n` +
                        `------------------------------\n` +
                        `**INFO**\n` +
                        this._getDebugInfo()

                    return SocialSharing.shareViaEmail(body, subject, [config.supportEmail]);
                })
                .catch(err => {
                    const alert = this._alertController.create({
                        title: this._translateService.instant('Error occurred'),
                        message: JSON.stringify(err),
                        buttons: [
                            this._translateService.instant('OK')
                        ]
                    });
                    alert.present(alert);
                });
        });
    }

After downgrading to 2.2.9, Device works again.

Most helpful comment

Thanks @biesbjerg and @ihadeed . It works now.

All 18 comments

Thanks, will fix this right now.

This is fixed now, please note that the static property device doesn't exist anymore on the class Device.

For example, Device.device.platform becomes Device.platform now.

Nice! Thanks!

How do we use it? Any help? Does it return a promise. I need to get the device UUID. I have updated the ionic-native package to the latest version.

Use Device.uuid

Sorry @samarthagarwal for not updating the other issue as well. What @biesbjerg said should work.

Not working. This is an instance property so I should do new Device().uuid, right? I have tested Device.uuid and it is not working.

@samarthagarwal did you update to latest version of ionic-native v2.2.11 ?

Yes I have.

screenshot_2

I had to restart VSCode before it understood that there was a "new API" for Device - maybe that's it?

I don't think VS Code has to do anything with it. I am getting a blank JSON object {} if I do the following.

alert(JSON.stringify(new Device()));

@samarthagarwal
image

You shouldn't do new Device. Just access it directly: Device

Thanks @biesbjerg and @ihadeed . It works now.

Hello everybody,
I am still experiencing this issue. I have 'ionic-native' 2.2.11 and cordova-plugin-device installed.

import { Device } from 'ionic-native';
platform.ready().then(() => { console.log( Device ); });

This code gives me empty object to console.

Device.uuid gives me also nothing.

Is there anything that I could have missed?

Thanks
Matej

@Math3v are you running on a device/simulator? are you using livereload?

@ihadeed result is the same when using livereload and device. Also, I have noticed the 'cordova-plugin-device' is not installed warnings, but there is no IonicNative script included in my index.html file.

@ihadeed sorry. I was accessing the Device in constructor. I moved the code inside ngOnInit() and it works just fine. 馃憤

Was this page helpful?
0 / 5 - 0 ratings