Can my phone receive Firebase push notification if I have installed an app that support it but I have never open it before - firebase

Do I need to open the app at least once in order for my phone to receive a push notification?

The must run at least once so it can collect a device ID token and send that to the backend that will send the message. Without that token collected, the app can never receive a message on that device.
Read more about it: What is FCM token in Firebase?

Actually you do not need the device token to send/receive the messages.
However, it is required that the user give permission to receive notifications, and that would only happen during runtime. I tested this and can confirm it works. The device token is only used to subscribe users to specific topics, but you can send a message to all users that have your app installed without needing to specify device tokens.

Related

Firebase push notification device to device

I am coding a React Native app and I using Firebase push notification service.
In my app, users can send message for each other and I want to notify them when they get message.
I found one way for native android I can code for react native it is not problem just I want to know if there is better way. I can make post to directly to Firebase service with using Http post.
This is the link which way I found: https://blog.usejournal.com/send-device-to-device-push-notifications-without-server-side-code-238611c143
I want to push notification to specific device without server, is there another way to do this?
Sending a message to a device with Firebase Cloud Messaging requires that you specify the FCM server key. As its name implies, this key is supposed to only be used in trusted environments, as knowing it allows one to send any message they want to all users of the app. For this reason it is not possible to secure send messages directly from one device to another device with FCM.
Instead you will have to run code in a trusted environment, such as your development machine, a server you control, or Cloud Functions. Your client-side application code invokes the server-side code, that ensures the call is authorized, and then calls the FCM API.
For more on this see:
How to send one to one message using Firebase Messaging
How to send device to device messages using Firebase Cloud Messaging?

Can I send push notification without using device token

I want to send automatic push notifications to my clients who are installing my flutter application. Can I do it without getting their device tokens. I am using firestore as my database
You can send messages to client apps using topic messaging, but each client app will need to be subscribed to the named topic. You will not be able to single out a specific device without a device token.

Firebase Cloud Functions - Send Notification user when they are online again?

I'm using fcm to send user notification and its triggedred by writing data to firebase database. But when user is offline notification send but never received and user cannot see it after they back online. How to send notification in all conditions.
Example: If user online send message normally but if user offline wait until user online and send them. How can I do this?
According to documents firebase cloud messaging already support what i want.
If the device is not connected to FCM, the message is stored until a
connection is established (again respecting the collapse key rules).
When a connection is established, FCM delivers all pending messages to
the device. If the device never gets connected again (for instance, if
it was factory reset), the message eventually times out and is
discarded from FCM storage. The default timeout is four weeks, unless
the time_to_live flag is set.
So FCM service wait until client device connected again.And sen notification when cliend connected. But if user hasnt connected for four weeks message deletes itself and never sent.
https://firebase.google.com/docs/cloud-messaging/concept-options#ttl

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

APNS Push Requests are successfully sent but passes are not updating

I have an app set up to generate passbook passes. The successfully install on the device and I can do manual (pull-down) updates.
Next I began to implement APNS. I'm using the enhanced request method to connect to the production environment, sending in an empty payload (as required) and it returns no error codes when I request a push notification, but my pass never updates and I see no requests hitting my server. I'm using my own device to test until I can get see an update for myself. No pass updates are received.
I then implemented the Feedback service in the hope that it might tell me something. I noticed this. If I pass in the push token, I receive a response which indicates that the device is not receiving notifications (even though the pass is set for automatic updates). The pass is not updated.
I'd appreciate any info into why the the push notifications do not seem to be arriving.
Thanks.
-Erich
One gotcha to check is that you are not using the sandbox APNS server. All Passbook push requests should be sent to the live APNS server.
Try enabling the additional logging option from the PassKit section of the Developer Settings on your device then connecting your device to Xcode and monitoring the console as you send the push. If the push is received, then you should be able to see your device requesting the serials to be updated from your webservice and you should also see your server's response.
Assuming you send a serial and that it matches the serial installed on your device, you should then see the device requesting the updated .pkpass bundle.
If no push is received, try toggling automatic updates on and off while monitoring the device console. It could be that the device is not receiving a valid registration (201) response or that you are using a stale token - you'll be able to see these via the console.

Resources