Worklight send push notifications without username - push-notification

I want to create an application which have 2 modes: non-logged-in and logged-in (having username).
I want to send push notifications to devices in both modes. The non-logged-in devices should receive notifications such as general announcements, new events, etc. The logged-in mode devices will also receive same notifications and few more.
Now what I want to do is to subscribe the device to receive notifications for non-logged-in mode then once the user logs in to his account from that device I want to unsubscribe the previous non-logged-in notifications.
I've read the answer to this question : Worklight: Push notification without User ID I think that I can play with onUserSubscribe callback when registering the user and unsubscribe the userId of the persistent cookie.
Is this a good idea ? Is there another suggestion ?

My thinking is that you could register an app to 2 event sources.
The first event source will handle the general notifications that an app should receive, whether a user is logged-in or not.
The second event source will handle the notifications for logged-in users.
When the app launches, subscribe to the first event source.
When the user decides to log-in, subscribe to the second event.
You should allow the user to unsubscribe from both if s/he so chooses, as well.
Additional information:
IBM Worklight 6.1 Information Center: search for "push notifications"
Push Notifications training module

So what you're trying to achieve is push notifications broadcast (send to all users). This is something that you'll be able to do with upcoming Worklight 6.2 release. You will not have to subscribe users according to username, but will be able to specify tags during subscription. And after that you'll be able to send push notifications according to this tags.

Related

Flutter - push firebase notifications to specific users without firebase auth

I am working with Firebase to push notifications and I don't use Firebase authentication on my app (I have my own system).
I didn't find an answer to this question:
Is it possible to push notifications to a specific user with firebase without Firebase authentication (and therefore, without a UID)? How?
The push notifications are not sent based on user, they are sent based on push notification token that is received when you register for push notifications (iOS & Android).
The push notification token will change in the case of uninstall/install and has nothing to do with what user is logged in in the app, you can send push notifications to apps that don't have users at all.
In order to target a specific user with push notification, you must do something called user segmentation, that is, filter user based on particular properties of these users. In general user segmentation is done by tracking user action and user properties and depends on the push notification platform in use. For example you can track user actions in the app, like user added product to cart, user has x products in cart and then send a push notification to all users that have more than 3 products in cart.
All the push notifications platform link the push notification token to the events triggered.
If you are using firebase, the most easiest way is to track user properties, there are a lot of tutorials on this part. Although, in my opinion, firebase tracking is kind of crappy.
One thing to note, since the push notification token is not linked to the user directly, in case there are two users (two accounts) using the same device they, they will receive push notifications on the same device, so don't send sensitive information via push notifications.

Does firebase cloud messaging allow targeting of push notifications to a specific device/user etc

I am trying out firebase cloud messaging (React-native-firebase) and it seems that I am only able to push notifications to all android/ios users, not specific users. Is there a way to target a specific user. Like if a user invites another user only send notification to that one specific user?
The flow can be this one:
User allow notifications on their device(s)
Grab the generated token and store it in the user document inside a tokens array.
(If the same user connects to your app in another device, add the new token in the tokens array)
If you want to target a specific user, get his UID and send a notification to their devices.
You can also subscribe a user to a topic and send a notification to users subscribed to that topic.
two way:
init
your client-side subscribe the topic.
subscribeToTopic("weather")
your client-side report the user property
setUserProperty("name","TOM");
Firebase Cloud Message Console
crate a notification item like this way
The flow can be this as follows:
User allow notifications on their device(s)
Grab the generated token and store it in the user document inside a tokens array.
(If the same user connects to your app in another device, add the new token in the tokens array)
If you want to target a specific user, get his UID and send a notification to their devices.
You can also subscribe a user to a topic and send a notification to users subscribed to that topic.

IBM MobileFirst Platform Event Source Push Notification

Let say user A subscribe event source push notification at device A at 10am and subscribe event source push at device B at 11am without unsubscribe. If my backend send the push message, both devices will receive the push message? I actually just want to send the message to the latest devices user have subscribed. Is there anyway to do this?
Like Idan suggested you can inspect push subscriptions in the database . Susbscriptions have an associated timestamp entry . With this you can determine the latest one for the user.
You can then use WL.Server.notifyDevice(userSubscription, device, options) or WL.Server.notifyDeviceSubscription(deviceSubscription, notificationOptions) to target a specific device.
If the user subscribed to two different event sources then yes, the user will receive notifications in both event sources...
There is no built-in mechanism that will prevent "duplicate" subscriptions (of the same user), so perhaps you could implement some sort of a cron job on your server to inspect the subscriptions table in the database and check that there are no duplicate subscriptions. If a duplicate subscription is found, delete the older one.

Push notification IOS/Android

I am writing back end for mobile app, we are sending pushes (something like one user add
another to buddies) he should accept it or decline via push notification(it is required), server got some feedback from notification, and do something.
I am familiar with two techniques about pushes, first I push directly on device using token, second is abstraction when user subscribes for channel and I send push notification on this channel. Id in my application is email, and I suggest to update device token in the database each time user login, and send push on it, but how should I identify device OS ?(IOS/Android)
1) How to scale it, if user have multiple devices, and when user will logout, and login from other device ?
May be there is common solutions for this problem.

Worklight: two users Same device Push subscription

I have a scenario presented by business team that: one person has device and he subscribed for Push Notification, later on his wife use the same device and subscribe for Push on her account.
Now in this case:
will Push go two times to the same device?
Or, the previous device subscription will be overridden
Plus, my App saves all Push notification messages on user's devices (as transaction history) , shouldn't be the problem!
To handle this scenario, what could be the possible options?
I am using Worklight Consumer 5.0.5
Thanks
Once you subscribe with different user on a same device the old subscription will be deleted. This is done for security reasons, e.g. in case you sell/loose/give your device new user should not get notifications of old one.

Resources