Sign In Register

How can we help you today?

Start a new topic

Custom behavior on touching push notifications in iOS and Unity

Hi everyone,


I'm working on a turn based asynchronous game where players are alerted that their opponent has taken a turn via push notification.


I'm working with Unity and building  for iOS at the moment.


I've gotten push notifications to work use Firebase Cloud messaging. When a push notification arrives and the user touches it, the game is opened. However it open up to the last scene it was in before the user closed it. 


I would like to be able to launch the Challenge that triggered the notification - the Challenge in which the opponent has just taken their turn.


So my question is, how do I know in Unity when the app is returning from being in the background (or closed) because the user touched a notification, and how can I store in the notification information about the Challenge that triggered it (specifically the challenge id)?


Thanks a lot,

Moshe


Hi Moshe


Triggering an event when a push notification is pressed has to be done on the client side.

For Unity if you are using FCM this would be done in the onMessageReceived listener that is part of the Firebase SDK.

GameSparks challenge messages hold data relating to the challenge  including challenge id in there payload.

The payload can be parsed and used in OnMessageReceived.


Regards

Katie


Hi Katie, 


Thanks, that's exactly what I'm trying to figure out now - how to parse the data 'payload' in the onMessageReceived listener. 


Here is what I'm doing at the moment in the onMessageReceived listener:


public void OnMessageReceived(object sender, Firebase.Messaging.MessageReceivedEventArgs e)
 {


 if (e.Message.Data != null)
 {
 var values = e.Message.Data;
 foreach (var item in values)
 {
 string temp = item.Key + " : " + item.Value + "\n";
 debugText.text += temp;
 }
 } 
 else 
 {
 debugText.text += "Message data is null \n";
 }
 } 


Receiving a message from Gamesparks does trigger the OnMessageReceived listener, and the message data isn't null, but data list is empty. 


Is this e.Messaage.Data field what you mean by payload? Is this the right way to parse it?


Thanks

Moshe

 Hi Moshe


The message is sent as a firebase message, you can read about firebase messages in there documentation here


Regards

Katie

Login to post a comment