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

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

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?

How to force logged in user's id token to refresh firebase from firebase admin

After changing user's customClaims, I want them to reflect immediately on the logged in client. How can I do that from nodejs admin?
I know how to do that from the client side using auth.idToken(true)
There is no direct way to force a client to refresh from the Admin SDK. The client itself will have to call the getIdToken(true) to refresh its token.
If you want to force a refresh, you will have to send a signal from the Admin SDK to the relevant client, probably through something like Firebase Cloud Messaging, or the Realtime Database/Cloud Firestore. The client can then, upon receiving that signal, refresh its token.

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

I want a way to accurately track user token removals & app uninstalls for my app in Android (GCM) and Apple (APNS)

I'm looking to accurately track users who decide they no longer want receive push notifications from my app OR users who delete the app.
https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/BinaryProviderAPI.html
From Apple documentation here there are some push error codes but none seem to fit clearly with user token removal. A
https://developers.google.com/cloud-messaging/http-server-ref#table9
From the Google docs this following error code seems to be close to what I want.
Error
Unregistered Device
HTTP Code
200 + error:NotRegistered:
Recommended Action
An existing registration token may cease to be valid in a number of scenarios, including:
If the client app unregisters with GCM.
If the client app is automatically unregistered, which can happen if
the user uninstalls the application. For example, on iOS, if the APNS
Feedback Service reported the APNS token as invalid.
If the registration token expires (for example, Google might decide
to refresh registration tokens, or the APNS token has expired for iOS
devices).
If the client app is updated but the new version is not configured to
receive messages.
For all these cases, remove this registration token from the app server and stop using it to send messages.
It seems here there is no way to differentiate between app uninstalls / token removals & token expiration
I already am sure uninstalls can't be track with Apple.

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