Sign In Register

How can we help you today?

Start a new topic

SocialRankChangedMessage and FCM not working as expected

I am currently trying to send push messages using FCM when one of my friends beats my score in the leaderboard.

There are some aspects of the behavior that is different from what I would expect:

  • I get 2 notifications, one when my score is beaten, if the app is not running, and an other when I open the app (the first one is sent by FCM and the second one is received by adding a listener to GameSparks.Api.Messages.SocialRankChangedMessage I suppose)
  • In the second one I build an Android notification by hand, in the first one a different notification is shown in the action bar, automatically by GS I imagine. However by default the notification had contents like &{data.title}, even after entering a value for Message Title in the console for SocialRankChangedMessage under Messages. The only solution that made content appear in the notifications was to directly edit the FCM JSON Template, but as it is stated to be Advanced I imagined there must be a more trivial way. 
  • By editing the FCM JSON Template directly I was able to receive and display notifications, however the special characters seems to be ignored, which is a problem as in my country (Hungary) most names contain some (I use Facebook to authenticate my players) 
  • The FCM notification is using an outlined version of the app icon, is there a way to change that?


Hi Balázs

1. If you only want the message to be sent as push in settings turn "Send Via Socket" to off.
2. It looks like the documentation on this needs to be updated.
    To set the FCM JSON template to read in from the message settings use
{
  "notification": {
    "title": "${title}",
    "body": "${summary}"
  }
}

 

To set the message templates to read in from cloud code

image


In cloud code

 

var msg = Spark.message("Push");
msg.setPlayerIds(Spark.getPlayer().getPlayerId());
msg.setSendAsPush(true);
msg.setMessageData({"title":"push test from pushTestEvent","body":"push test subTitle"});
msg.send();

 

 

3. This is a known issue that is in our backlog to fix,we don't have a timeframe for this fix yet.


4.You can add a custom icon to your notification by adding the name of the to the json

  "notification": {
    "title": "${title}",
    "body": "${summary}",
    "icon": "myIcon"
  }

 The image called "myIcon" here will need to be added to the projects res/drawable folder, if you don't have this folder already create one.



Regards

Katie

  

 

Hi Katie,


Thanks for the quick response, let me add some summary / questions:

  1. So for the same message the message is delivered via socket after login even if it was previously delivered by push?
  2. If I understand correctly for every message type the FCM template should be modified from null to the template you provided, otherwise empty messages are being sent by default?
  3. Is there a way to work around this, so the special characters could be delivered via push, or I just have to wait for the fix to be shipped?
  4. Understood, thank you.

Best, 
Balázs

Hi Balázs

1.Messages are sent via push, socket or both at the same time, Push messages are displayed when the app is not open and socket messages are display when caught by the listener and displayed when the app is open.

2.Yes in the message settings you should provide the FCM JSON template.

3. The only work a around for this at the moment is to use SparkHttp to call the the FCM rest API and manually set the content-type to utf-8.

Regards
Katie

 

Hi Balázs

In regard to number 3 we have an update, there is a work around for special characters.

The following function will encode the string as UTF-8.

function encode_utf8(s) {
  return unescape(encodeURIComponent(s));
}

Regards
Katie

Hi Katie, 


Thanks for the tip. Where should I call this function? When saving player data?


Thank

Balázs

Hi Balázs


You can call this in your cloud code where you are setting the message text.

For Example 


function encode_utf8(s) {
  return unescape(encodeURIComponent(s));
}

So for example in Cloud code 

var message = encode_utf8("Séan");

function encode_utf8(s) {
  return unescape(encodeURIComponent(s));
}


var msg = Spark.message("pushTest");
msg.setPlayerIds(Spark.getPlayer().getPlayerId());
msg.setSendAsPush(true);
msg.setMessageData({"title":message,"body":message});
msg.send();


Regards

Katie

Hi Katie, 


Thanks for the answer,

Unfortunately this solution wont work for me, as I use mostly system notifications (like ChallangeLostMessage, or SocialRankChangedMessage).


Thank you anyways.

Balázs

 Hi Balázs


For system messages you can use the scripts in cloud code->UserMessges

You can set the message in code by setting script data.

For example to set the main message text in the script

Spark.setScriptData("summary","string message");

In the message set up message template field read in the script data

${scriptData.summary}


Regards

Katie

Login to post a comment