How to get time from firebase_messaging push notifications? - flutter

I am making a Flutter app on Android that receives notification from Firebase Cloud Messaging service. Is there any way for me to know the time that my phone received the notification? When my onMessage,onResume and onLaunch functions triggered I noticed that there was a "google.sent_time:" key but I do not know how to convert that into the actual time.

sent_time should be milliseconds since epoch. You can convert this timestamp to a date with the following snippet:
new DateTime.fromMillisecondsSinceEpoch(sentTime);

Related

Flutter Notification appears twice when app is in background

I am using firebase and flutter_local_notifications package to show the notifications sent from api (laravel) and when app is closed (background mode) the notification is repeated but in foreground it appears once
This is my code
https://github.com/KamlaSaad/Notification/blob/main/not
There are two types of messages: notification and data.
Notification messages are handled by the FCM SDK automatically. Most likely the first one comes from SDK and the second one from your handler.
Notification messages which arrive in the foreground are not handled by the SDK.
See Message types for details.

how to send scheduled push notifications to flutter app

I have flutter app which data ,I will get through api and there list of appointments data with that data I need to remind user by notification so I tried local notification, background fetch in flutter but not working as expected
Any other proper way to remind notification before appointment time like push notification and i'm using backend C# for writing api
Look into https://github.com/winsw/winsw/releases
A wrapper executable that can run any executable as a Windows service.

Does FCM push notification registration need to be done once or each time the app is opened

I'm using PushNotifications of capacitor for ionic app to send FCM (firebase cloud messages).
The PushNotifications.register() is needed to trigger the 'registration' event with the push token. When the 'registration' event received we use PushNotifications.addListener('registration',()) to get the token and keep it in order to use it to send FCM.
It seems to me these actions need to be done only once, but I saw somewhere that the token is changed from time to time so maybe this is the reason I saw several examples that do this registration each time the app is opened.
What is the right approach? do it once or each time the app is opened?

Firebase database notifications

I have an iOS app that I am working on and every time I change anything in the firebase db it notifies my app. I am looking to stop all those notifications as I want to implement notifications myself and just have firebase be a datastore.
I am using .observeSingleEvent everywhere but the app still gets notified every time the DB updates.
As you probably guessed I am new to Firebase but I was hoping some knowledgeable firebase person can help explain to me how to turn off all firebase notifications.
IMPORTANT: I do need to have the capability to do my own push notifications so I cannot simply stop the iOS App from registering for notifications. Right now Firebase and my notifications conflict and I get duplicates.
Thanks for any help!!
There is one way to make a firebase fire a push notification when node is changed. You should check Cloud Functions. There must be an information about when fire and what to change.

Send Notification as message with Firebase Cloud Messaging in Swift

I'm trying to create a Chat App. When the app enters background and if he receives a message, then a notification must appear.
What I understand is that FIRMessaging.sendMessage() sends something to the cloud. But how the other device is gonna receive it ? It cant be continually looking for messages that are targetted to him...
I would like to understand how to use this fonction and what are the parameters to pass in it. So far and with the current documentation, I couldnt do it.
[[FIRMessaging message]sendMessage:(nonnull NSDictionary *)message
to:(nonnull NSString *)receiver
withMessageID:(nonnull NSString *)messageID
timeToLive:(int64_t)ttl;
What should I put in the receiver ? It's userId in firebase ? or what ?
In the exemples they talk about SENDER_ID + "#gcm.googleapis.com"
which confuses me cause it looks like it's either my Id or the Id of the firebase App..
I cant even figure out if i'm trying to send an upstream or downstream message (dont understand)
Well all I can say is that I really get my head around it...
https://firebase.google.com/docs/cloud-messaging/upstream#handle_upstream_message_callbacks_1
Thanks!
Firebase Cloud Messaging and Firebase Notifications (which is built on Firebase Cloud Messaging) handle this automatically for you. From the documentation of Firebase Notifications:
When your app is in the background on a user's device, notifications are delivered to the system tray. When a user taps on the notification, the app launcher opens your app. If you want, you can also add client message handling to receive notifications in your app when it is already in the foreground on the user's device.