Search code examples
javascriptvisual-studio-cordovaonesignal

Uncaught TypeError: Cannot read property 'getIds' of undefined at window.plugins.OneSignal.getIds


I have a cordova project in my Visual Studio 2017. If I run cordova requirements I get the followin:

Java JDK: installed 1.8.0
Android SDK: installed
Android target: installed android-19,android-21,android-22,android-23,android-26,Google Inc.:Google APIs:19,Google Inc.:Google APIs:23
Gradle: installed

Debugging in chrome work perfectly, but in my device I get the followin error:

"Uncaught TypeError: Cannot read property 'getIds' of undefined".

That is a fragment of my javascript code:

function registerOneSignalDevice(callback) {

    window.plugins.OneSignal.getIds(function (ids) {

        setStorage("device_id", ids.userId);
        setStorage("device_platform", device.platform);
        if (callback != undefined) {
            callback();
        }
    });
}

Any idea...


Solution

  • OneSignal recommends using Cordova 6.4.0 or newer. You may want to update to the latest OneSignal Cordova SDK as well.

    The getIds method was deprecated in the 2.1.0 release. You should update to their SDK 2.2.5

    For Cordova and variant SDKs like ionic, Phonegap and IntelXDK you can get the UserIds aka PlayerIds using the getPermissionSubscriptionState method and addSubscriptionObserver.

    For more on using getPermissionSubscriptionState see: https://documentation.onesignal.com/docs/cordova-sdk#section--getpermissionsubscriptionstate-

    For adding subscription observers see: https://documentation.onesignal.com/docs/cordova-sdk#section--addsubscriptionobserver-