When to register to push notification in ionic - push-notification

I am implementing ionic push notification to my app.
I want to know when shall I identify and register user. Is that should be done once for all (when first boot of the app), or I need to request for registration each time I start the application, so I refresh user's tokens ?

Related

How to handle push notifications for same user in more devices, more browsers

I have an hybrid website created with Ionic on Firebase, so I have even the PWA version, an android version and an iOS version, the user can be free or authenticated.
Now I am in a problem 'cause I dont have idea how to handle the push notifications when an user could access the first time my website, then he choses to receive notification and I store on my database his/her token to send push notifications, everything ok this user has 1 token.
Now this user become registered then when he access the website I dont know this is the same user as before then I receive a new request to store a new token.
At this time this same user has 2 token in my database.
Now if the user another day will visit my website with another browser, for example firefox and accept again the notification then he has now 3 tokens on my DB.
If the same user now even install the PWA version I will get another different token and my system will store even this, now this user has 4 tokens.
Keeping going further with this examples an user could collect 6 or more tokens stored on my database.
The problem is that if now I send a notification, this user will be overhelmed by my informations and is going to receive 6 or more notifications every time I send out 1.
Which is the best way to handle this situation?

When should I save push token to my server in Android?

My app has a little dialog where users can click to opt-in for push notifications. On iOS when they press this, they get the permission request and then if they approve it, I send a POST request to my server with their push tokens.
Since, Android remote notification permissions are granted during the app installation, when do I send this POST request to my server with their push tokens?
Save it on first launch.
Using AsyncStorage you can save user first launch and save the token at this time

STOP Push notification after logout

I'm using angular in my project which user swPush. The notification works fine, but even after user1 logged out am getting the push notification. I don't want to push notification to the logged out users.After the user2 logged in both user1 and user2 getting notifications on the same device, this confuses the user. I want to restrict the user to get notification only when they logged in. How can I do achieve this. Is there any method.
I already try unregistering the service workers using
navigator.serviceWorker.getRegistrations().then(function(registrations) {
for(let registration of registrations) {
registration.unregister()
}
})
But after using this, both the users are not getting notification.
Thanks and regards
You should not unregister the Service Worker registrations because, well, that unregisters all of them. Unregistering Service Worker prevents any push logic from happening since web push is a layer on top of Service Workers - you need to have Service Workers registered and active in order to use push notifications, right?
You have two options if you only think about "showing the notifications":
When the user logs out, stop sending the push notifications. Of course this means that the web app logic has to inform your server somehow that now the logout event happened and precisely who it was (which of the possible different browser sessions of this particular user). Of course your server should already have information about the logout event.
Keep track of the logged in user in the browser (your JS code) and only show push notifications relevant to that user. You need to somehow distinquish between the receivers of the push notifications and the active user sessions in the browser and most likely handle it in self.addEventlistener('push', ...) in the SW.
If you think about privacy/security standpoint, the option #2 is of course wrong. If you only hide/not show the logged-out user's notifications, it means you're still sending them from the server. The notifications could include private information and whatnot.
So really you should go for #1. That's the right way to implement this. It leaks no information from the logged-out users, keeps the users' push subscriptions separate, and saves bandwidth.

UWP Push Notification - Send message externally

I have Register my app for the windows store (by doing steps 1 to 13) as in the link
Now notification works when I'am adding notifications in developer account. Now I want to know that can I send the notification message to my app externally? For example when I enter a text on html/php page and press a button, that entered text should be send as a notification message to all app users (both foreground and background). How can I link all this?
if you registered your app to get a push notification channel your getting an uri where you can reach your app. In your php script you need to send notifications to that uri. So your app have to register the uri in your backend so you have it available in your sender. then when you push the button you need to send the notification to that uri. see more here: https://learn.microsoft.com/en-us/windows/uwp/design/shell/tiles-and-notifications/windows-push-notification-services--wns--overview

IBM MobileFirst V7.1 Push Notification Issue

We are developing hybrid mobile application in IBM MobileFirst V7.1,Java 1.7v.
In this application we are developed push notification using Adapter Based Authentication.
In our application we are sending push notification using Adapter based Authentication.
The notification is delivered based on userId.
Here for first time to a particular userId,I'm able to send notification.
After that when user trying with another userId I'm unable to send notification,getting an error "user already exist please logout".
Error in Log:
Cannot change identity of an already logged in user in realm 'pushAppRealm'. The application must logout first.
for this in client side I'm checking whether user is authenticated or not by using "WL.Client.isUserAuthenticated(realm)" ,it is always retuning false.
I also tried with logout option when user clicks on login button I'm logging out the user and again authenticating the user -
here also I'm facing same issue "user already exist please logout".
Push notifications should be dispatched from the server , not from the client.
In your flow, the very first time you authenticate , you will assign a user identity into your user realm. Now from the client , you invoke the adapter procedure that sends out the notification.
The second time around , you pass another userid. This time you try to authenticate again with the another user (all within the same session). It amounts to forcing a new identity when the realm already has one.
This is why you see message in the server that says - "Cannot change identity of an already logged in user in realm 'pushAppRealm'. The application must logout first."
The right approach to be adopted is :
Authenticate into the realm.
Subscribe for Push. This assigns the user identity from 1) to your subscription.
Either use poll mechanism or REST API calls to dispatch notification. Pass the userids as arguments in the REST calls.

Resources