I want onesignal to be able to send push notification to a specific device.
How do I capture the device id of the device ?
And what API do I use to push to that specific device ?
Thanks.
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.
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.
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:
Tag your devices with a unique tag with sendTag
.
OneSignal.sendTag("is_test", "true")
Create a new Segment on the OneSignal dashboard named test devices.
If you're looking to send notifications to a specific user device: (Can be used for User-to-User notifications)
player_id
with the getIdsAvailable
SDK method.
userId
from the getIdsAvailable
callback if the pushToken is not null or blank to your server.include_player_ids
to the userId on the PostNotification SDK method or on the create notification REST API call.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With