Example with Facebook application in iOS, use Apple Push Notification Service (APNS). I think when Facebook server see an new feed or new friend request, it will send a message to APNS. After that, APNS will push notification to client, who is logging in that facebook account. My question is :
Why APNS know which device logging in that facebook account ?
How APNS can send message to that client exactly (why APNS know client's IP address) ?
As I know, Push Notification also a technology use in Windows Phone ( Microsoft Push Notification Service), and Android (Cloud to Device Message).
Thanks.
Well APNS (Apple Push notification Service) works on a per device per app unique ID.
You push you message to this unique ID and it get deliver on the users device.
Your app must request this ID and pass it to the server wich will send out the notifications.
The ID is that create by the APNS API, thus Apple knows that the ID belongs to that device and app.
I guess that the windows and android will work in the same way.
Related
Right now I'm trying to send mobile push notifications to my phone when someone publishes a message to SNS. I'm confused about what services I have to use. Do I have to use a 3rd party service like Firebase Cloud Messaging/GCM to send mobile push notifications? Or can I send it directly from SNS to my phone.
In AWS docs it's a bit contradicting to me.
https://docs.aws.amazon.com/sns/latest/dg/sns-mobile-application-as-subscriber.html
It says:
To begin using Amazon SNS mobile push notifications, you need
the following:
A set of credentials for connecting to one of the supported push
notification services: ADM, APNS, Baidu, FCM, MPNS, or WNS.
A mobile app that is registered and configured to use one of the
supported push notification services.
So that means we have to use a third party service right? But however in one of the AWS SNS tutorials:
https://docs.aws.amazon.com/sns/latest/dg/mobile-platform-endpoint.html
it says we can create a platform endpoint for my mobile device so that it can recieve push notifications. I am extremely confused, do we have to use a third party service or can we send SNS push notifications directly to our phone?
I checked stackoverflow and the answers are not clear to me either
Can Amazon SNS push notifications directly to mobile devices?
Amazon SNS Sending direct push notification to individual device
Can someone please clarify this for me?
AWS SNS manages and abstracts different push notification services.
For AWS SNS to be able to make use of the appropriate push notification service, it would need a platform endpoint. It would need to know which platform (i.e iOS) an app is built.
it says we can create a platform endpoint for my mobile device
To create a platform endpoint, you would need a certificate coming from the Push Notification provider.
Example: .p12 is a certificate from Apple which will require "Push Notification" feature to be enabled.
Once a platform application is created, the app would need to register a unique device token to AWS SNS.
This device token is generated by iOS or Android to uniquely identify the device. The app can only generate the device token if it's properly signed by a certificate from the Push Notification provider.
do we have to use a third party service
Yes you need a third party service to:
generate the certificate with push notification feature enabled
generate the device token associated with your physical device
properly sign the app using the certificate
or can we send SNS push notifications directly to our phone?
AWS SNS manages this for you by matching device endpoints to the correct device token. Then invoking the appropriate push notification service. (i.e APNS, GCM).
I am completely new to push notifications, FCM and Ionic.
I have followed this tutorial to create a push notification using Ionic 2 and it works.
It feels like there is no use of device-id (generated at the client side) at the server side in this ionic doc.
I am unable to understand how to send different push notifications to different users using the same app and same server code?
Also whats the purpose of FCM (Server key and Sender ID) here?
What's the exact workflow, does it works like a web-socket?
Thanks for the guidance :)
1. It feels like there is no use of device-id (generated at the client side) at the server side in this ionic doc.
The device-id (aka the Registration Token) is the identifier for the specific device you intend to send the push notification to. Saving this value in your App Server is important so that you can send push notifications specifically towards it (should you decide/need to) later on.
2. I am unable to understand how to send different push notifications to different users using the same app and same server code?
As mentioned above, this is where the device-id (Registration Token) comes into play. For each device, there is a corresponding unique id, which you'll have to specify in your payload.
3. Also whats the purpose of FCM (Server key and Sender ID) here?
You can refer to the FCM docs for these:
Server Key - A server key that authorizes your app server for access to Google services, including sending messages via Firebase Cloud Messaging. You obtain the server key when you create your Firebase project. You can view it in the Cloud Messaging tab of the Firebase console Settings pane.
Important: Do not include the server key anywhere in your client code. Also, make sure to use only server keys to authorize your app server. Android, iOS, and browser keys are rejected by FCM.
Sender ID - A unique numerical value created when you create your Firebase project, available in the Cloud Messaging tab of the Firebase console Settings pane. The sender ID is used to identify each app server that can send messages to the client app.
To keep it short, Server Key is for authenticating, Sender ID is for identifying from which project the message is coming from.
4. What's the exact workflow, does it works like a web-socket?
Not really. Having a web-socket means that having the connection always active until decided to be closed, where in FCM (or even before, GCM), the lifecycle is like this:
Lifecycle Flow
Send and receive downstream messages.
Send a message. The app server sends messages to the client app:
The app server sends a message to GCM connection servers.
The GCM connection server enqueues and stores the message if the device is offline.
When the device is online, the GCM connection server sends the message to the device.
On the device, the client app receives the message according to the platform-specific implementation. See your platform-specific documentation for details.
Receive a message. A client app receives a message from a GCM connection server.
Send and receive upstream messages. This feature is only available if you're using the XMPP connection server.
Send a message. A client app sends messages to the app server:
On the device, the client app sends messages to the XMPP connection server. See your platform-specific documentation for details on how a client app can send a message via XMPP.
The XMPP connection server enqueues and stores the message if the server is disconnected.
When the app server is re-connected, the XMPP connection server sends the message to the app server.
Receive a message. An app server receives a message from the XMPP connection server and then does the following:
Parses the message header to verify client app sender information.
Sends "ack" to the XMPP connection server to acknowledge receiving the message.
Optionally parses the message payload, as defined by the client app.
I am unable to understand how to send different push notifications to different users using the same app and same server code?
It's your task. Your message must contain all neccessary data (i.e. userId) so your app knows which of the users are target for that message.
I have two questions related to Android Push Notification System:
What is the working principle of this system? The client sends its own IP to the Google Cloud Messaging Service (for example when it switches its own IP)? So it a sort of pooling?.
How do you know that Google Cloud Messaging Service "looks into" the content of the notification message (created in the server and dispatched to the client)?
Answering the question about how GCM service contacts the client, the GCM client contacts GCM to create the connection. You are correct that device addresses change as the device disconnects and reconnects so GCM cannot initiate the connection from the server side.
This connection is maintained as much as possible and is not created for specific messages.
The registration id identifies the device and app and allows GCM to route the message to the device, if it is connected. If it is not connected, GCM needs to wait until the device reconnects.
What is the working principle of this system? The client sends its own
IP to the Google Cloud Messaging Service (for example when it switches
its own IP)? So it a sort of pooling?
I'm adding an image here describing how GCM works.
This is a step by step presentation. You need to get the push registration ID first when your application launches. So if you've a backend server to send some push notification in your application, you need to pass the registration ID to your backend server. So when you need to send a push notification, your backend server will send the push directly to GCM with the targeted registration ID. GCM manages to push the notification in your device when your device comes online.
So this is not any kind of pooling. The only thing GCM needs to know is the registration ID of your device when it comes online and tries to communicate with GCM. Once your device is registered, GCM sends the push notification using that registration ID.
How do you know that Google Cloud Messaging Service "looks into" the
content of the notification message (created in the server and
dispatched to the client)?
This question is not very clear to me. As far as I have understood, you wanted to know how GCM understands to whom it needs to send the push notification when the notification is coming from your backend server. If this is your question, then I think I have answered it already in the previous section of my answer.
GCM doesn't need to look into your notification content to know the destination of the push notification. As I said earlier, when your application launches, it requests for a push registration ID from GCM and when it receives an registration ID, you might have to pass the registration ID by calling a service of your backend server. The server then knows to whom it might send some notification.
So, when its time to send a notification to your client application, the backend server sends the notification to GCM with the registration ID you sent to your backend server earlier. GCM then handles sending the push notification to the client when the application comes online.
Hope that helps!
I was wondering how android push framework is able to distinguish data recieved via GCM and forward it to the appropriate android application for which it was intended ?
Can anyone let me know how it is done ?
You question : how android push framework is able to distinguish data recieved via GCM and forward it to the appropriate android application.
From your question it looks like you willing to know about data
workflow & Client Server architecture that exists in applications
which are using the GCM service.
As per google’s documentation “Google Cloud Messaging for Android (GCM) is a service that helps developers send data from servers to their Android applications on Android devices”. GCM is a service provided by Google for developer that helps developer to send data from server to any number of Android devices.
Simplified Application Specific Work-flow:
The push notification can be broadcasted either to the mass audience
or a select set of users. Mass audience is targeted when the
notification has to be sent about a marketing campaign. A subset of
users are targeted when a personalized information has to be sent.
The below steps explains how push notification works on android devices:
First android device sends sender id, application id to GCM server
for registration.
Upon successful registration, GCM server issues registration id to android device.
After receiving registration id, device will send registration id to our server.
Our server will store registration id in the database for further use.
Whenever push notification is needed, our server sends a message to GCM server along with device registration id (which is
stored earlier in the database).
GCM server will deliver that message to respected mobile device using device registration id.
This can also be understand using following figure
An Example Workflow:
So, from above images it easy to understand that whenever the android
application is first installed by the user, then it registers itself
to GCM server, and obtains unique GCM ID, then it's our Host servers
responsibility to keep this newly registered Registration ID of the
android user into Database, and then it will be used whenever server
side application willing to send the message to that particular
android user.
So, let us consider one case; suppose an Server wants to send Some data to Android User, which has already registered it's GCM ID 1234567 when it's first time installed, and as it's in the server's database the server application will fetch it from DB, and simply make a HTTP POST request to the GCM server in JSON format, which will have registered user's GCM ID along with the data to send , in same way the GCM Server has the record of all the Registered GCM/Android Clients, it directly forwards that message to the intended android user, and android app in user's phone will raise and Notification alert, to indicate an push notification has arrived.
Hope This answers an question!
GCM stands for Google Cloud Messaging.
Every push notification receive on any Android device is sent by the GCM only.
sender -> GCM -> Android Device
when sender sends an push notification then it goes to GCM. GCM receives that push and forward it to particular Android Device by its Unique device id.
GCM can't deliver Push without Unique Device ID.
while implementing push notification there are two important things, application key and server key ... these are unique Keys.. using these keys GCM identifies the application to whom push notification is related
I am currently using GCM to push notifications to both an iOS and Android version of my app.
With Android, I am able to process any message I send from the server client side, and then decide what I want to do with it. For example, I can receive a request, check client-side if the user has push notifications enabled, and THEN send a push notification from the client side.
The question is: Are there any client side methods of sending push notifications for iOS, similar to Android?
To receive message, an iOS application needs to register with both Apple Push Notification service (APNs) and the GCM connection server. When a client app registers with GCM, it receives a registration token, which it must then send to the app server (the APNs device token is not sent to the server). The client app must store a boolean value indicating whether the registration token has been sent to the server.
You can follow this documentation on how to set up a client app on IOS.
Based on this SO question, It is very simple to implement APNs and GCM. You can follow this steps
When APNs (iOS Devices) and GCM (Android Device) registers for Push Notification on Apple and Google Server it generates a unique token for every device.
After that, you need to save that device token, with your device id or user id (unique id on your server for device) and the OS of device.
IOS device is sending this information on your server (backend) you can use this JSON format- {"token":"abcdedfgehik2bd3d3ff3sffssdff","os":"iOS","userid":34}
This is how it will work.
You request device token from APNs as usual.
You need to send that token to GCM service with provided API.
Then GCM sends back a another token.
Then send that token to app server.
App server can send notifications using that token.
Try also to check this for more information.