capacitor official push Notification plugin with firebase (FCM) received with some delay time - push-notification

I'm using capacitor official push Notification plugin with firebase cloud messaging (FCM) and all thing is ok but the problem is the delay .. in Android and IOS the notification received within 2 to 4 min. after publishing the notification from FCM Console. thanks for advice

finally solved!.. the problem was in the FCM console, and when I'm using FCM Endpoints to send notification to FCM there is no delay ! and by the way the request as follow :
URL : https://fcm.googleapis.com/fcm/send
Method : POST
Authorization (Bearer Token) : server Key (you can find it in your FCM Console)
Body (Json object data) as follow :
"registration_ids" : ["userToken", ..],
"notification" : { "body": "notificationText", "title" : "notificationTitle"},
"data" : { "key" : "value"}

Related

Send a notification to all my Android devices with REST Firebase

I want to send notifications to all the android devices within my app. Actually, I can send a notification to a single token and it looks like this:
{
"to": "dwh6BFzxAOE:APA91bFenA-tySAKuNtiJGCeULewqYOwRDwfZMe4hWGN10Gx2S3sEoArZOvn_0pQihsDOtx6upcmwBbrTT2gG-rpYmPmXOvuzqMRoZy_rM6xCPyviXIn-JAAtoEEq2S4wEtGgnOBLR41",
"notification": {
"title": "My title",
"body": "This is the message"
}
}
But I don't understand how to send this notification to all devices at once. Without subscription.
I am using flutter for the apps, and I have created a react js web service to call this API REST and POST notifications.
To achieve Push Notifications via Firebase, you need to implement FireBase Cloud Messaging to push notifications to devices.
From the docs,
An FCM implementation includes two main components for sending and receiving:
A trusted environment such as Cloud Functions for Firebase or an app server on which to build, target, and send messages.
An iOS, Android, or web (JavaScript) client app that receives messages via the corresponding platform-specific transport service.
See the documentation for server setup, or you can also use FireBase Functions. It sounds like you want to integrate Firebase Functions with Cloud Messaging. I haven't done this before, but here is a blog post doing this for a Flutter Web project:
https://medium.com/#umeshnalinde7/flutter-cloud-messaging-with-firebase-functions-firestore-android-175904a15537

How do i send a image along with FCM-push notification for nativescript?

I use nativescript-vue and this plugin for sending push notifications:
nativescript-plugin-firebase,
How do i send an image along when i send a push notification?
In my nativescript-vue project i receive the notification like this:
firebase.init({
showNotificationsWhenInForeground: true,
onMessageReceivedCallback: async (message) => {
})
How do i show an image in the notification?
I have tried with including image: "url" and that dosnt work. I think there is way to show a image in the notification because on the firebase panel there is an option to send along a image.
The firebase notification plugin only acts as a receiver and handler of notifications in this case. If you want to send a remote notification with image, you are going to do that with your notification sender; and in this case on Firebase.
If you just want to quickly send or test a push notification with an image, you can do so by going to Firebase Console > Cloud Messaging.
Then just add your image in the respective field.
Now, in most cases in production you would want to do this progmatically on your backend instead of going to Firebase Console. You can do that by using Firebase FCM SDK.
In our case, we usually do it via API calls something like:
POST https://fcm.googleapis.com/fcm/send
BODY
{
"to": "/topics/user_{{userId}}",
"notification" : {
"body" : "This is a Firebase Cloud Messaging Topic Message!",
"title" : "FCM Message"
}
}
Header should include a key "Authorization" with value:
key=<YOUR_FCM_KEY_HERE>
You can get your FCM key by going to Firebase Console > Project Settings (the gear) > Cloud Messaging. You can check this doc for more details on sending.
Lastly, if you really want to handle the notification image via your app (not suggested), you can force so by using a local push notification by force handling the remote push notification and doing a local push notification with your own desired image.

React native with firebase (push) notifications

So I have registration/login handled on my side using Laravel. I tried adding React-native-firebase so after login I could subscribe to topic like notifications/:userId so I would get notifications only for that user as currently every user is getting push notifications.
I can't find any guide on how to make this so it will work when app is in "dead" state or minimized.
I'd appreciate any help.
Thanks
You can use the below mentioned library for firebase integration.
https://rnfirebase.io/
Firebase has the Firebase Cloud Messenger, which has some notification control and badges from notifications built into it. I hope that helps, here is a link React-Native (https://rnfirebase.io/docs/v3.1.x/messaging/reference/messaging) and Firebase Docs (https://firebase.google.com/docs/reference/js/firebase.messaging)
You have generate fcmtoken after user log in, and save it to database.
After that from server side you have to fetch the fcmtoken for that particular user and call firebase pushnotification api / service.
Notification Payload :
{
"message":{
"token":"bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
"notification":{
"title":"Portugal vs. Denmark",
"body":"great match!"
},
"data" : {
"Nick" : "Mario",
"Room" : "PortugalVSDenmark"
}
}
}
If you want to send message/notification to multiple devices minor change is
tokens: ["token1", "token2"]

Push Notifications on Samsung Gear S3 with Tizen 2.3.2.1

I am working on Push Notifications for Samsung Gear S3 using Tizen Wearable Web Application. My application got Approval from the Tizen team to use the Push Notifications. I followed the guidelines of Push Notifications and integrated the Push Notifications code in my application.
I am able to receive RegId using
tizen.push.registerService(service,registerSuccessCallback,errorCallback);
Now when I am connecting to the Push Service using below method,
tizen.push.connectService(notificationCallback, errorCallback);
I am not receiving any notifications. I tried on both emulator and real device (Samsung Gear S3 Class 2.3.2.1).
When I sent the push notification from the server, I got the success response from the push server
Request :
{
"regID": "XXXXXXXX",
"requestID": "273f0307",
"sender": "Madhu",
"message": "badgeOption=INCREASE&badgeNumber=1&action=ALERT&alertMessage=Hi I am a Test Notification"
}
Response :
{"results": [{"regID": "XXXXXXXXX","requestID": "273f0307","statusCode": 1000,"statusMsg": "Success"}]
}
Even though I am receiving success response from the Push Server its not delivering the Push Notifications to the device/emulator.
Please provide the solution how can I get the push notifications deliver to my application.
I was having a similar problem. I discovered an error in the logs that indicated that it was looking for the "appData" field. The documentation says that you can include EITHER "appData" or "message", but it appears that you must have BOTH present in 2.3.2. Tizen 3.0 doesn't seem to care.

Firebase Cloud Messaging set up but not receiving push notifications from Firebase console

I've been trying to debug Firebase push notifications for quite a long time now, and got no luck. I believe I have set up provisional profiles and APNs certificate correctly. When I do not include the method
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
FIRInstanceID.instanceID().setAPNSToken(deviceToken, type: .unknown)}
App receives notifications in foreground when sent from Firebase Notification console because it gets printed out, but it does not receive notification in background.
If I add the above method to it, it does not receive notification in foreground and background.
Anyone knows what is wrong?
I have already enabled push notifications, remote notifications, and I have setup the APNs certificate correctly. I have also tried reinstalling the app but it does not work. I have also tried all the stackoverflow posts already regarding this issue.
The code snippet that you've provided is for manual mapping of APNS token with the device registration token. Basically, you need to explicitly add this when the swizzling is disabled for your app.
Make sure to use the right token type: FIRInstanceIDAPNSTokenTypeSandbox for the sandbox environment, or FIRInstanceIDAPNSTokenTypeProd for the production environment. If you don't set the correct type, messages are not delivered to your app.
In addition, make sure that the priority is set to High in the Advanced options section when creating a new message in the Firebase Notification console.
If you're using a data message type to send notification to the client apps via FCM, then it is an intended behavior.
{
"to" : "bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1...",
"data" : {
"Nick" : "Mario",
"body" : "great match!",
"Room" : "PortugalVSDenmark"
},
}
Per the Firebase documentation:
On iOS, FCM stores the message and delivers it only when the app is in the foreground and has established a FCM connection.

Resources