Error on getting PlayerId from OneSignal service

Hi

I try to implement the PushNotification feature in my app using the OneSignal service.
Everything works at the moment, but now I’m trying to get the PlayerId from the OneSignal service but
I get an error in the try catch.
But the error says nothing :-((

This is my code:

        var notificationOpenedCallback = function (jsonData) {
          console.log('notificationOpenedCallback: ' + JSON.stringify(jsonData));
        };
  
        window["plugins"].OneSignal
          .startInit("2f288ebf-95ba-4f06-9348-fe6a63035ccb", "119423241284")
          .handleNotificationOpened(notificationOpenedCallback)
          .endInit();
  
          window["plugins"].OneSignal.getIds().then((id) => {
            alert('playerid: ' + id);
          });  

Attention
I only get an error if I add/use the getIds() method:

         window["plugins"].OneSignal.getIds().then((id) => {
            alert('playerid: ' + id);
          });  

What do I wrong?

All tips are welcome :slight_smile:

I found the problem :slight_smile:

The problem was, that getIds() did not return a promise.
(I saw this snippet everywhere, in the web, and they said it worked on their side…!!! how can this be ?! :-))

This is my code after the change, which is now working on my side:


        var notificationOpenedCallback = function (jsonData) {
          console.log('notificationOpenedCallback: ' + JSON.stringify(jsonData));
        };

        var getPlayerIdCallback = function (response){
          console.log('playerId:' + response.userId);
          console.log('pushToken:' + response.pushToken);
        }
  
        window["plugins"].OneSignal
          .startInit("2f288ebf-95ba-4f06-9348-fe6a63035ccb", "119423241284")
          .handleNotificationOpened(notificationOpenedCallback)
          .endInit();
  
        window["plugins"].OneSignal.getIds(getPlayerIdCallback);

Update
I’m using the plugin directly (without import).
You can import the plugin as well with:

import { OneSignal } from '@ionic-native/onesignal';

I think you can call getIds() as a promise :slight_smile:
Don’t forget it to register OneSignal as a provider in the app.module!!!