multiple endpoints with same token in AWS SNS - push-notification

I am using AWS SNS for sending push notifications and I have used this article for the implementation http://mobile.awsblog.com/post/Tx223MJB0XKV9RU/Mobile-token-management-with-Amazon-SNS
I am storing the token and the endpoints in the server for sending the push notifications, but the problem is with GCM when the reg_id gets changed and pervious reg_id is still active then the aws update the pervious endpoint with latest token, due to which I have got two endpoints with same reg_id and when I am sending the push notification then it is getting delivered twice.
I have searched everywhere but I am not able to find the solution, how do I update my server DB to delete the older endpoint.

Related

Push notifications requests sent to Firebase logs

I'm struggling to find a way to see the logs of all push notifications requests sent to my Firebase project.
Since I'm using SNS, and it uses Cloud Messaging API (Legacy) to send these messages, I need to find out why I'm receiving 200 responses but the messages are never delivered.To see the Payload coming from SNS would be really helpful.
Any suggestions?
Thank you!!

Effect on HTTP legacy protocol server key of adding or removing APNS Certificate to existing Firebase Cloud Messaging project

I have FCM push notifications implemented on a server.
I want to additionally send APNS notifications via that server by sending as a FCM message that is forwarded by Firebase to APNS.
To do that I understand I need to add APNS certificate to the firebase console.
FCM push notifications on my server were implemented some time back when FCM HTTP legacy protocol was available and server API keys were visible in the Firebase console (I got the key from somewhere so I guess it was there).
My question is if I add (and perhaps later remove) an APNS certificate to my firebase console production project will that affect the validity of my existing server API key in any way. It is important that FCM continues to work seamlessly.
It doesn't seem possible to get a FCM HTTP legacy protocol server key now. If there is a way to do this then I could try this myself on a test project.

How to set notification channel when sending messages via rest api?

I've been implementing Notification Channels in my android app to support recent android versions.
You can set the notification channel id when sending messages from the firebase web console, but I was not able to find out how to set the channel id when sending messages via fcm rest api.
Notification channels are not mentioned in the reference (https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages), but I am pretty sure there must be a way to set the channel id.
The key name I was missing is android_channel_id
I found the key name in the Legacy HTTP Server Protocol docs (https://firebase.google.com/docs/cloud-messaging/http-server-ref)

Unable to receive XMPP upstream messages after FCM migration

I have my XMPP server which was working with GCM. I upgraded to FCM as per google says though I am able to receive notifications from FCM notification console, not able to receive any upstream messages with FireBaseMessaging.send() ... If any one has done this migration please help.
Note : I have a XMPP server which was working and able to receive upstream messages via GCM. (After migration to FCM it is not receiving any messages even though the end points are changed. Am i missing anything from docs)
This is fixed ! while using both (GCM, FCM) dependency in my project I was using a string resource default-project_id from GCM dependency. I now removed and replaced that with the project_id and it is fixed. So endpoint change is not mandatory.
Make sure you update the server endpoints. Note that the new FCM version of gcm-http.googleapis.com/gcm/ is fcm.googleapis.com/fcm/ (without "http"):
Change GCM endpoint
gcm-xmpp.googleapis.com
to FCM endpoint
fcm-xmpp.googleapis.com
source: Migrate a GCM Client App for Android to Firebase Cloud Messaging
For more information, Check this Upstream message syntax for FCM and how to send Upstream messages on Android.

Push Notifications through Firebase

Yesterday Google has announced a new set of tools for Firebase, one of them was Notifications the ability to send notifications from server to devices which are using my app.
But can we now notify users when they receive a new message?
And if not, is there a way around to achieve this?
Looking at the documentation, this doesn't seem currently possible automatically. Here is a possible way to accomplish it "manually" with another server:
Subscribe a user to it's own user ID
In android
FirebaseMessaging.getInstance().subscribeToTopic("InsertUserIDHere");
In IOS
[[FIRMessaging messaging] subscribeToTopic:#"/topics/InsertUserIDHere"];
Setup an outside server that checks every sent messages. When a message is sent, the server should create a notification that includes the recipient's user ID as the topic.
Look here for more info.
You can send messages to group of users (targeting a specific "topic") or to a single device (targeting a Firebase Cloud Messaging token).
To subscribe a device to a topic use:
FirebaseMessaging.getInstance().subscribeToTopic("topicName");
To obtain the device token use (*1) :
FirebaseInstanceId.getInstance().getToken();
Then you can use the Firebase Notificaitons web console, or the FCM server API if you want to send messages from your server.
See: https://firebase.google.com/docs/cloud-messaging/downstream#sending_topic_messages_from_the_server
Notes:
[1] getToken() can return null if the token is not yet available.
You can use the callback onTokenRefresh() to be notified when the token is available and when the token is rotated.
See: https://firebase.google.com/docs/cloud-messaging/android/client#sample-register

Resources