Comments (5)
The details of the expected behavior are here
https://firebase.google.com/docs/cloud-messaging/android/receive:
- When the app is running in the foreground the notification is routed
from the service (that handles the notification) to the SDK which then
fires the callback. - When the app is in the background and running we can route the
notification to the app, as it's running :) - When the app isn't running / killed, our service runs which receives
the notification and caches it. When the user clicks on the notification
the notification is routed to the app when it's launched.
If you want to customize what happens in the notification when the app
isn't running you'll need to subclass our service
(com.google.firebase.messaging.cpp.ListenerService which implements
FirebaseMessagingServices
https://firebase.google.com/docs/reference/android/com/google/firebase/messaging/FirebaseMessagingService)
and replace the reference to it in your Android manifest. You can then
override the onMessageReceived() method to customize the behavior in your
service. Obviously, this is not particularly cross platform as there is no
way to do this on iOS.
Does this clarify the behavior you're seeing? Are you able to reproduce the errant behavior with our sample application?
Cheers,
Stewart
from quickstart-unity.
I guess there is no more feedback since my last reply, I hope it's working for you. Please reopen if you still have issues.
from quickstart-unity.
I am having the same issue.
I am not getting the Data Messages. Here is the complete detail of what i am doing and what is happening:
- I am using Unity 5.6.1f1 and latest Firebase SDK for Messaging.
- I am using a php script to send the messages.
- The notification messages are displayed fine. Custom data fields in the "Notification Message" (in t the "data" key) are also retrieved fine in the "OnMessageReceived" method, with the following script:
`<?php
$json_notificationMessage = '{ "data": {
"command": "hit",
"challengeScore": "35"
},
"notification":{
"title":"Hello Title",
"body":"Hello Body",
"sound":"default"
}
"to": "DEVICE_TOKEN",
"priority": "high"
}';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Authorization:key=SERVER_KEY'
));
curl_setopt($ch, CURLOPT_POSTFIELDS, $json_notificationMessage);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
curl_close($ch);
echo $output;
But the PROBLEM WITH THIS is that i have to click on the notification to get the OnMessageReceived function called.
- Now i am sending the FCM Data Message so that i don't have to click on the notification to get the OnMessageReceived function called. But i am not receiving the Data Messages when my app is in background or closed (quit). Following is the php script that i am using for sending the Data Message:
$json_dataMessage = '{ "data": {
"command": "hit",
"challengeScore": "35"
},
"to": "DEVICE_TOKEN",
"priority": "high"
}';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Authorization:key=SERVER_KEY'
));
curl_setopt($ch, CURLOPT_POSTFIELDS, $json_dataMessage);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
curl_close($ch);
echo $output;`
- I read the following note from the "About FCM Messages" page of Firebase documentation
"Note: If you want to send messages consisting of only custom key-values to an iOS device when the app is in the background, set custom key-value pairs in the data key and set content_available to true."
so i added the content_available:true so that my jSON now looks like this:
$json_dataMessage = '{ "data": {
"command": "hit",
"challengeScore": "35"
},
"to": "DEVICE_TOKEN",
"priority": "high",
"content_available":true
}';
And i received the Data Message BUT ONLY when my app was in foreground (visible on screen).
- My requirement is that i want to get the Data Payload even if a user does not clicks on the notification. According to FCM, Data Message is the way to do this but i am not getting that custom data payload if the app is in background or closed.
Please help in this regard on how can i achieve this functionality.
Thank-you.
from quickstart-unity.
@muneebattamindravel the behavior of data messages differs between Android and iOS
For Android details see
https://firebase.google.com/docs/cloud-messaging/android/receive
When messages are received in the background, if the application's message receive service is running it's possible to perform an action in response to a message. We have this documented in the C++ guide (the Unity SDK is built on top of the C++ SDK) https://firebase.google.com/docs/cloud-messaging/cpp/client#custom_message_handling_on_android
On iOS when an app is in the background (it's really not running) messages are received via APNS in which case data will only be received by the application when / if the message is clicked and the message is routed to the app when it starts running again.
from quickstart-unity.
from quickstart-unity.
Related Issues (20)
- The updated SDK seems to have solved the connection issue! Much appreciated HOT 1
- Android: Push notification messages are not received when the application is closed! HOT 3
- FirebaseMessaging.MessageReceived triggers multiple times on receiving single push notification HOT 9
- Generation of the Firebase Android Resource File Failing Again HOT 3
- Coding Rules are not there! HOT 2
- Cloud functions not working with Quickstart project HOT 2
- corrupted com.google.firebase.firebase-messaging-unity-***.aar HOT 2
- [Bug] "FirebaseMessaging.RequestPermissionAsync()" is incorrect. HOT 1
- User Property values coming in late
- Cannot upload debug symbols for Android to crashlytics HOT 1
- How to change Dependencies download destination path? HOT 1
- Unity Firebase App works in editor but not in build HOT 1
- Newbie - Guidance Needed About Firebase Projects Management (On Firebase Dashboard) HOT 1
- Crash on iPhone 6 on iOS 12 with Realtime Database HOT 2
- Targeting iOS version numbers requires upgrading to SDK version 6.24.0 or later
- When proper Firestore Unity support? HOT 2
- Unity [FirebaseCore][I-COR000003] The default Firebase app has not yet been configured. HOT 1
- messaging/testapp not working HOT 3
- Cloud Messaging / build problems HOT 5
- GetValueAsync() in Realtime Database often enters infinite wait HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from quickstart-unity.