Sign In Register

How can we help you today?

Start a new topic

Error Push Notifications Firebase - Special characters


We think we´ve found a bug in the platform, regarding firebase based push notifications on Android (we don´t know if this occurs on iOS too, we are only using firebase on android at the moment).


Firebase deletes some characters like acute accents (á é í ó ú and others), ñ, etc when we send push notifications.


We think this could be because you don´t specify to use the UTF-8 charset in your requests from GameSparks to Firebase or something similar.


To reproduce the problem, you just have to send a message through cloud code, with the following code:


msg.setPlayerIds([""]);

msg = msg.setMessageData({"title":"notificación prueba","body":"bódy","type":"tipo"});

msg = msg.setSendViaSocket(false);

msg = msg.setSendAsPush(true);


The notification arrives without the accented characters. 


In our own events, when we send messages the native C++ side receives it correctly:


WebSocket callback: {"@class":".ScriptMessage","data":{ "contestname" : "contest_daily" , "contestid" : "59537319900bea04e91d3a33" , "rank" : 29},"extCode":"ContestClosedMessage","messageId":"5959e4c276803304f5e0b01d","notification":true,"playerId":"5959e45a2d91abaf5d16fc2a","summary":"Has quedado en la posición 29.","title":"Concurso finalizado"}


However, the Java side receives it incorrectly:

public void onMessageReceived(RemoteMessage remoteMessage) {


    Log.d(TAG, "FROM: " + remoteMessage.getFrom());


    //Check if the message contains data

    if (remoteMessage.getData().size() > 0){

        Log.d(TAG, "Message data: " + remoteMessage.getData());

    }


    //Check if the mesage contains notification

    if (remoteMessage.getNotification() != null){

        Log.d(TAG, "Message body: " + remoteMessage.getNotification().getBody());

        sendNotification(remoteMessage.getNotification().getTitle(),remoteMessage.getNotification().getBody());


        setNotificationType(remoteMessage.getData().get("type"));


    }

}


D/MyFirebaseMsgService(10214): Message body: Has quedado en la posicin 29.


The firebase config is totally standard, we haven´t done anything special.


Could you check this? 


Please tell me if you need any further info on this.


Thank you very much.


1 person has this problem

Hi Mahei Innovation

This is a known issue and is currently in our backlog to be fixed.
I currently do not have a estimated time for when this will be fixed.
I can update you here as soon as the fix is released

Regards
Katie

 

Hi! Is there any update on this?
If not, is there any kind of workaround? We will release our game soon, and spanish has many accent marks.

Best regards

 

Hi Mahei Innovation

I don't have an update on when this will be done.
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

 

I am also looking forward for this, also on the external http callbacks doens't work as well, I had to do a workaround to convert them to unicode code and then convert it back inside the game

I assume this same issue would cause emoji in push notifications to appear as "?" on android? When I send the same notification using the Firebase console directly the emojis turn up fine.

Any update on this issue?

Hi all

We don't have an ETA on when this issue will be fixed yet.
We will post here as soon as we have an update for you.

Regards
Katie

 

Hi All

We have a work around for this problem until a fix is released.

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

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();

I hope this solution will work for you until we have UTF-8 FCM encoding built in.

Regards
Katie


Hi Katie


The work around is only working for cloud code initiated messages, all messages from GameSparks itself, e.g. GameWonMessage will still have this bug


Building a backend for a non english speaking audience this is a major problem.


Best Simon


2 people like this

Following this discussion as we have the same problem. A fix or a more complete workaround for this issue would be really appreciated, as we are approaching scheduled release.


2 people like this

We have the same issue with Danish letters. If we want to use the Segments for each language in the Messages section, it will not work with the provided fix. We then have to localize in Cloud Code which is really sad.
UTF-8 (or 16) really should be standard encoding these days.. 
Any ETA on a fix? 

FYI, the fix that Katie posted works, but only if you don't use the iOS push service directly. You have to use FCM for both Android and iOS users, and you can't of course use the build in Messages feature that GameSparks provides and have to handle localization and segmentation in Cloud Code, so it is a bad work around.. 

Any new regarding this issue?

Login to post a comment