Emoji在推送通知中无法显示,而是显示问号或显示Unicode。

huangapple go评论82阅读模式
英文:

Emoji does not display in push Notification instead it display question mark or display unicode

问题

表情符号在推送通知中显示为Unicode字符。例如:如果我们有类似于"\ud83d\ude0a"的文本。这是笑脸表情符号的代码,它会显示为Unicode字符,有时在推送通知中显示为问号。

在代码或服务器端是否还需要做其他操作?任何帮助都将不胜感激。我们在后端使用Java。

JSON示例:

{
   "to": "c2rMPP0eK04Ro0FJDgMflH:APA91bEydhoB0VU5W6PxJLnIRoFqOk5npEjlWzBlvdyBlX1Cp72t0bYxDyepP5Z9mWFQ2XYeUPw8PDo3QqT6Anh27wqnkBRbabTYKn0tByOZOMU6oRlrGur-efxN9_-8LlOmDZceg9Kl",
   "notification": {
      "body": "Hello",
      "title": "This is done manually. \uD83D\uDE0A"
   }
}

我们尝试了以下方法:

byte[] emojis = user.getEmoji().getBytes();
String emojisAsString = new String(emojis, StandardCharsets.UTF_8);
Integer emojiCodePoint = emojisAsString.codePointAt(emojisAsString.offsetByCodePoints(0,0));
char emojiChars[] = {Character.highSurrogate(emojiCodePoint), Character.lowSurrogate(emojiCodePoint)};

注意:如果我们从Postman中执行这些操作,它可以工作,但从后端执行时却无法工作。

英文:

Emoji appears as a unicode characters in push notifications. i-e : if we have text like "\ud83d\ude0a". This is the code of SMILE EMOJI which displays as unicode characters or some time it display question mark in push notification.

Is there anything else need to do in code or on server side. ? Any help would be appreciated. we are using java at backend side

Json example :

{
   "to": "c2rMPP0eK04Ro0FJDgMflH:APA91bEydhoB0VU5W6PxJLnIRoFqOk5npEjlWzBlvdyBlX1Cp72t0bYxDyepP5Z9mWFQ2XYeUPw8PDo3QqT6Anh27wqnkBRbabTYKn0tByOZOMU6oRlrGur-efxN9_-8LlOmDZceg9Kl",
   "notification": {
      "body": "Hello",
      "title": "This is done manually. \uD83D\uDE0A"
   }
}

We try this things

byte[] emojis = user.getEmoji().getBytes();
String emojisAsString = new String(emojis, StandardCharsets.UTF_8);
Integer emojiCodePoint = emojisAsString.codePointAt(emojisAsString.offsetByCodePoints(0,0));
char emojiChars[] = {Character.highSurrogate(emojiCodePoint), Character.lowSurrogate(emojiCodePoint)};

> Note : If we fire this things from postman then it is working but not
> working when it fire from backend

答案1

得分: 1

"\u{D83D}\u{DE0A}"
英文:

Try this string:

"\u{D83D}\u{DE0A}"

答案2

得分: 0

如果您正在从数据库中读取数据,请尝试更新您的数据库驱动程序。例如,如果您正在使用MySQL,请使用'mysql-connector-java:5.1.47'或更高版本。

英文:

If you are reading from DB, try updating your DB driver. Like if you are using MySQL, use 'mysql-connector-java:5.1.47' or higher.

答案3

得分: 0

"\uD83D\uDE0A" or "\u{D83D}\u{DE0A}" is not encoded emoji.

You should encode it like \u{1F600} \u{1F616}:

"\u{1F600} \u{1F616}"

Refer link:

Emoji unicodes

Unicode in iOS

It works on playground. Check if it works on the notification panel.

英文:

"\uD83D\uDE0A" or "\u{D83D}\u{DE0A}" is not encoded emoji.

You should encoded like \u{ and }:

"\u{1F600} \u{1F616}"

Refer link:

Emoji unicodes

Unicode in iOS

It works on playground. Check if it works on notification panel.

huangapple
  • 本文由 发表于 2020年8月14日 17:31:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/63410219.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定