Reputation: 4278
I have a web application and mobile application to manage user parcels. Now, i want when a user receives a parcel, send a notification from web application to him on mobile application.
I used OneSignal and connected my mobile app successfully, but don't know which and how call an api to send notification to specific user?
Also, I read the documentation, but couldn't find any way and example for this requirement
Upvotes: 0
Views: 519
Reputation: 3170
The most popular way to send push notification to mobile devices is by using Google Firebase push notification.
Every device is tracked by unique device token generated by Firebase ( Android or iOS ).
Solution for your Usecase:
Whenever user tries to login into your application just trigger an API call to backend.
That API will put an entry to the database with userId and device token.
When you going to send push notification just get the device token from the database based on userId using Firebase SDK.
Example:
To send notification for multiple device ids that may be Android or IOS.
You can use MulticastMessage in fireBase.
MulticastMessage multiCast = MulticastMessage.builder()
.putAllData(new HashMap<String, String>() { put("message":"hi"); })
.setApnsConfig(ApnsConfig.builder().build())
.setAndroidConfig(AndroidConfig.builder().build())
.addAllTokens(Arrays.asList("devicetoken1", "devicetoken2"))
.build();
For reference : https://firebase.google.com/docs/cloud-messaging/send-message
Upvotes: 1