GithubHelp home page GithubHelp logo

Comments (5)

stewartmiles avatar stewartmiles commented on May 28, 2024

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.

stewartmiles avatar stewartmiles commented on May 28, 2024

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.

muneebattamindravel avatar muneebattamindravel commented on May 28, 2024

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.

stewartmiles avatar stewartmiles commented on May 28, 2024

@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.

muneebattamindravel avatar muneebattamindravel commented on May 28, 2024

from quickstart-unity.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.