Sign In Register

How can we help you today?

Start a new topic
Answered

JSON structure showing in Notification (Firebase)

I have configured a push notification using Unity/Firebase for iOS and Android, using and Event to schedule the module and push a message to the player. iOS seems to work fine so far. Android occasionally sends the JSON structure ${data.title} ${data.body} as the push notification, ignoring the message being passed.

This does not happen with every message, it seems to be random. Pushing a message directly from the Firebase console works perfectly.


ScriptMessage template

{

  "notification": {

    "title": "${data.title}",

    "body": "${data.body}"

  }

}


Integrations Template (FCM)

{

  "notification": {

    "title": "${data.title}",

    "body": "${data.body}"

  }

}

[CODE IN MODULE]

var msg = Spark.message(null);

msg.setPlayerIds([Spark.getPlayer().getPlayerId()]);

msg.setMessageData({"title": "Test Title","body": "Test Message"});

msg.send();


Best Answer
Hi Daniel

I think setting the message as null is causing the problems.
Can you set up a ScriptMessage Extension.
For example in the portal, Go to Configurator->messages->ScriptMessages Extension
Create a new ScriptMessages Extension for example called "test_Push"
In "tesh_push" set up set the FCM JSON Template (Advanced) with the following

{

  "notification": {

    "title": "${data.title}",

    "body": "${data.body}"

  }

}


In cloud code


var msg = Spark.message("test_push");

msg.setPlayerIds([Spark.getPlayer().getPlayerId()]);

msg.setMessageData({"title": "Test Title","body": "Test Message"});

msg.send();


Regards
Katie

 


Hi Daniel

${data.title} being displayed means that the data in the cloud code isn't being sent correctly.
Meaning this line isn't working properly.
msg.setMessageData({"title": "Test Title","body": "Test Message"});

Is there any differences in how this is set for notifications or is it all hard coded for testing at the moment?

Regards
Katie

 

I am actually attempting to send a random message/title combination after a set interval. It definitely works sometimes, but every now and then a random message will come through with the structure and no message.

(new to cloud code and gamesparks, So if there is a better way to structure this, I am open to suggestions!)


var msg = Spark.message(null);

msg.setPlayerIds([Spark.getPlayer().getPlayerId()]);

var titleArray = [

    "Need to kill some time?",

    "Has another day passed?",

    "Crabs - Carrots - Catasaurus Rex",

    "Release the KRAKEN!"

    ];

var textArray = [

    "Grab a taco and run with Catasaurus Rex.",

    "Spend some quality time wtih the C-Rex.",

    "Have you released the Kraken today?",

    "There is no better way to waste time, than with C-Rex.",

    "Stop reading click bait garbage and get to running!"

];

var textBody = textArray[Math.floor(Math.random() * textArray.length)];

var textTitle = titleArray[Math.floor(Math.random() * titleArray.length)];

msg.setMessageData({"title": textTitle,"body": textBody});

msg.send();

Answer
Hi Daniel

I think setting the message as null is causing the problems.
Can you set up a ScriptMessage Extension.
For example in the portal, Go to Configurator->messages->ScriptMessages Extension
Create a new ScriptMessages Extension for example called "test_Push"
In "tesh_push" set up set the FCM JSON Template (Advanced) with the following

{

  "notification": {

    "title": "${data.title}",

    "body": "${data.body}"

  }

}


In cloud code


var msg = Spark.message("test_push");

msg.setPlayerIds([Spark.getPlayer().getPlayerId()]);

msg.setMessageData({"title": "Test Title","body": "Test Message"});

msg.send();


Regards
Katie

 

That seems to have done the trick! Thank you very much. :D

Login to post a comment