Why is the Azure Notification Hub backend registration process 2-legged? - azure-notificationhub

I'm trying to use my .NET backend to register/send push notifications to my mobile devices.
Therefore, i'm following this article.
From my understanding:
POST: api/register registers the PNS handle the device has with Notification Hub.
PUT api/register/{registrationId} creates or updates the registration with Notification Hub.
Now my question is, why does this need to be a 2 stepped process?
Why can't the app on start/load, simply always call POST: api/register with the PNS handle, which can then create the registrationId (if necessary), and then use the existing (or newly created) registrationId to create the registration with ANH? Why does the app even need to store the registrationId?
Can someone please un-confuse me :)

As for the Put and Post in the article, it is to separate the registration id creation (POST) and registration id registration (PUT).
As for the REST APIs for Notification Hubs, https://msdn.microsoft.com/en-us/library/azure/dn495630.aspx will be the "create and update" that you are talking about.

Related

Sending React Native Notification on database update?

I have an AWS Postgres database, an API layer, and a React Native application. One user is trying to communicate with another (and this will be stored in the db) I want to let the intended user know that a message awaits them with a notification. I'm not using expo. I've looked at using OneSignal but the functionality seems limited in this aspect (unless I'm missing something) I've prefer to use React Native Local notifications. Does anybody know how to achieve this with either OneSignal or RNLC?
You want 2 users to communicate with each other, and via a notification to let them know they have a new message. You can send push notifications directly to a user by using the player id and our REST API. The player id will target only the user the notification was meant to be sent to.
https://documentation.onesignal.com/reference/create-notification

Is it possible to create Custom Push Notifications with a REST service backed server?

I have an OpenEdge database, I have created a REST Service and am able to CRUD to it from the outside World.
I have created a Nativescript app that can pull data from the REST service etc, but now i want Push notifications.
I know about the Progress Kinvey backend, and Firebase backend with their push notification features but i don't want to use them.
is there a way to create my own Push notifications on my REST server etc?
So first I would like you to understand how Push Notification works just to make sure we are on same page,
Once your app is installed, you can query for a unique token and save it in your backend for future use. Whenever you want to send a push notification, you have communicate with APNs (Apple Push Notification Server) / FCM (Firebase Cloud Messaging) in order to send a push notification to your iOS / Android device using the unique token you acquired earlier.
So now you must use Firebase as that is the only way you can communicate with Android, yet you may choose to communicate with APNs yourself. But in my opinion, it will be a overhead for you as both have their own protocols, you will have to distinguish your tokens between iOS & Android, use appropriate protocols etc.,
I would suggest you to go with just Firebase plugin (until you are super familiar with APNs already), so you don't have to worry which platform the token belongs to, update / revoke invalid tokens over time etc., FCM has pretty decent APIs & Documentation that can make your life easy here.
i strongly recommend you to see my answer here answer here.
from it:
when you want to pull anything from place_1(e.g. api) to place_2(e.g. browser_client) you most have an identifier of the
place_1_resource (which commonly is the uniform-resource-locator of
api)
when you want to push anything from place_1(e.g. notification_central_server) to place_2(cellphone_client) you most
have an identifier of the place_2_resource
if you don't have any identifier for a cellphone which you want to
send it a notification, your server dont know where to send that
notification so we need a resource_identifier_like for cellphones
which is actually a device_token_like and you have just one approach
to get this device_token_like and that is the FCM/APNS

Real-time notifications with Firebase & Ionic

NOTE : Don't say it's possible duplicate of this, Read through.
Think of a simple TASK Management application which can have n number of users. Say User A can create a task & assign it to User B. I want to show a notification to User B.
I am using Firebase as BAAS and following code-snippet prints on console only when there is a task assigned to User B. To simplfy, Users collection in Firebase has a node called tasksAssignedToThisUser array and callback function will be watching tasksAssignedToThisUser location. Whenever a new task gets added to that array, callback function gets executed. Here is the code snippet:
var rootRef = firebase.database().ref();
rootRef.child('users').child(loggedInUserID).child('tasksAssignedToThisUser')
.on('child_added', function (newMessageSnapshot) {
console.log('Someone assigned a task to this user.');
console.log(newMessageSnapshot.val);
});
Everything works fine until here.
What I have understood by reading Firebase docs & other post's on SO about Push notifications or Firebase Cloud Messaging is:
Firebase Notifications lets users easily send messages to reengage and
retain users, foster app growth, and support marketing campaigns.
Before you can write client apps that use Firebase Cloud Messaging,
you must have an app server that meets the following criteria:
...
You'll need to decide which FCM connection server protocol(s) you want
to use to enable your app server to interact with FCM connection
servers. Note that if you want to use upstream messaging from your
client applications, you must use XMPP. For a more detailed discussion
of this, see Choosing an FCM Connection Server Protocol.
This is definitely not what I want and maintaining a server for sending push notifications makes sense when bulk messages needs to be pushed to large number of devices. So I didn't name my question as Real Time Push Notifications.
I see a function being executed, which meets my use-case and I just want app to display a notification to the user in his mobile system tray on that callback function execution.
I am using Ionic 1 for developing app, completely new to Firebase and Ionic too. If there is a simple serverless approach that Firebase itself provides which can suffice my requirement, then I would be more than happy to hear about it.

Bluemix Mobile Push Notification Service, how to register by consumerId

When send push notification messages, consumerIds can be specified as target. But when register the device, I don't see where to supply the consumerId in the SDK doc.
Register iOS Devices
Register Android Devices
Can you let me know how to register with the consumerId?
Thanks,
Jen
Currently there is no way to register a consumerId / userId through the Android and iOS SDKs. This is a feature that existed prior but was removed due to security issues when dealing with the public facing REST APIs. It is my understanding that work is being done to reintroduce the functionality but I know nothing more than that.
That said it is possible to recreate the functionality through the REST API (https://mobile.ng.bluemix.net/imfpushrestapidocs/#!/devices/put_apps_applicationId_devices_deviceId)
In short what you would need to do it register the device normally through iOS or Android, then execute the REST GET devices/{deviceId} using the deviceId obtained at the time of registration. From there you could copy off the data, insert your desired consumerId and then execute PUT devices/{deviceId} using that data to update the device registration with the new consumerId.
The answer I posted here goes over that in a little more detail
How to register a userId to Bluemix Push Notifications services?
Again unfortunately it's pretty convuluted to execute at this point while we wait on the native SDKs to reacquire the functionality. In some cases it may be wiser to just create your own mapping of deviceIds to consumerIds and use deviceIds as your push parameter.
Have you check this documentation of the rest API for IBM Push Notification?
https://mobile.ng.bluemix.net/mbaas-api/?cm_mc_uid=70457747682413998998889&cm_mc_sid_50200000=1456154344#!/push/sendMessage_post_21
There's optional parameters for consummerIds and deviceIds.
There's also this more complex API documentation of IBMPushService:
https://mobile.ng.bluemix.net/mbaas-api/docs/JavaScript/IBMPushService.html?cm_mc_uid=70457747682413998998889&cm_mc_sid_50200000=1456154344

Could one iOS application support multiple push notification registration?

This is the first time that I approach the push notification service and I'm little bit confused. I 'd like to have just some conceptual help, not code.
I need to build an app that should receive and register for different kind of notifications. For instance in my app I'd like that users could register for PROMO notifications category and NEWS notifications category, I'd like that they could choose which one they want to be notified.
Reading the Apple doc, that was not so clear to me, it seems that once the app device is registered I receive just one token and seems impossible to receive more tokens for different kind of registration(NEWS and PROMO for instance), because the token is related to the app and the device. Is that correct?
The other thing that is not so clear to me is, if a device is registered for a specific notification is it possible to send the notification only to a set o devices?
If nothing of that is offered by Apple Push services do you think that is possible to manage everything like that:
-I register the app device for notification if (PROMO || NEWS) are selected
-I get the token
-I send the token to my server giving also as additional info about the service which the user wants to subscribe
-The server (provider) register the token and the kind of subscription (PROMO || NEWS)
-Later when I have a notification to push I ask the server all the tokens registered for that specific category and then I send the notification only to those devices registered for that category.
Thanks for helping me out I'm really confused.
"Reading the Apple doc, that was not so clear to me, it seems that once the app device is registered I receive just one token and seems impossible to receive more tokens for different kind of registration(NEWS and PROMO for instance), because the token is related to the app and the device. Is that correct?"
YES
The other thing that is not so clear to me is, if a device is registered for a specific notification is it possible to send the notification only to a set o devices?
YES, you need a DB where you connect a Push Token with the related Services (promo | news). If you have a new Promo Push Message you send the message to all related token. on the app site, everytime the user change the categorie (promo / news) you should prpvide these infos to your service with the push token.
These are all problems that you have to solve yourself on the server side. The push service simply provides a means to send a single message to a single device. You have to figure out yourself which messages you want to send to which devices. Each message has to be sent individually, there's no way to "broadcast" a message to all your users directly.
You could think of the push tokens as email addresses – of course, one email address might be subscribed to different newsletters from the same publisher, but it's the publisher's job (yours) to figure out whom to send which newsletters, not the email provider's (Apple's).
You should think of the push notification registration like my I send the user push notifications. Not what kind of push notification can I send the user.
Then you need to do serverside filtering on you categories, like the ones in your example promo and news.
The perferance of the user should be stored on your server, so you will know what kind of notification to send to which user.