Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OneSignal how to send Push to specific device - ionic

Tags:

I want onesignal to be able to send push notification to a specific device.

  1. How do I capture the device id of the device ?

  2. And what API do I use to push to that specific device ?

Thanks.

like image 778
Axil Avatar asked Jun 10 '16 01:06

Axil


People also ask

How do you send push notifications to your ionic 4 app with OneSignal?

When you now navigate to the settings and select Keys & IDs of your app you will find a ONESIGNAL APP ID and REST API KEY. These 2 values are needed in order to connect your server to the OneSignal REST API to create new notifications, but for our next step we only need the app id for our Ionic app.

Does ionic support push notification?

Ionic is easy to integrate with Firebase and Firebase Cloud Messaging, which allows you to enable push notifications quickly. You can benefit from Firebase to easily set up the cloud environment for your app.


1 Answers

Here is a copy of OneSignal's guide on sending a notification to an individual device:

If you're looking to send notifications to only your test devices:

  1. Tag your devices with a unique tag with sendTag.

    • Example: OneSignal.sendTag("is_test", "true")
    • For an exact example see OneSignal's API Reference for the SDK you're using.
  2. Create a new Segment on the OneSignal dashboard named test devices.

  3. Press "Add Filter" and select "User Tag" as the "Filter Type".
  4. Enter is_test equal to true.
    • The values you used in step 1.
  5. When creating a new notification, remove "All" and add your test devices segment.

If you're looking to send notifications to a specific user device: (Can be used for User-to-User notifications)

  1. Get the user's player_id with the getIdsAvailable SDK method.
    • See OneSignal's API Reference for the SDK you're using for example code.
    • For testing you can use the 'Player ID' shown on the user page on the dashboard.
      • You can force kill your app and open it again to bring your device to the top of the list.
  2. Send the userId from the getIdsAvailable callback if the pushToken is not null or blank to your server.
  3. Set include_player_ids to the userId on the PostNotification SDK method or on the create notification REST API call.
like image 116
Gdeglin Avatar answered Oct 30 '22 16:10

Gdeglin