Ionic 2 - Onesignal - Get player_id

Asked

Viewed 216 times

3

I use Onesignal for push notifications in an Ionic 2 application. To send notifications targeted to specific users I need to recover player_id from Onesignal.

Does anyone have any idea how to retrieve this platform id?

  • You are using the plugin ionicnative?

1 answer

1

I found how to recover the player_id from the Onesignal plugin, and it’s actually quite simple. In app.component.ts, I added the code:

  window["plugins"].OneSignal.getIds(ids => {
    console.log("player_id: " + ids.userId);
  });

With this, I get the user PLAYER ID, making it possible, for example, to send targeted push notifications to the specific user.inserir a descrição da imagem aqui

  • Perfect. And this method runs as soon as the Ionic application is started which already allows you to save this number and send it to your backend, as was my case. Thus, my api processes the request and already returns to the device.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.