Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem to send emoji to Push Notification #7

Closed
alexleandrom opened this issue Apr 15, 2013 · 13 comments
Closed

Problem to send emoji to Push Notification #7

alexleandrom opened this issue Apr 15, 2013 · 13 comments

Comments

@alexleandrom
Copy link

Hi everybody, I am trying to send pushnotification for ios app.
end I am having a problem to send emoji on this push.

I have this text on my database:

"\ue415 Vei na boa vou dar um tiro nesse push"

when I try to send this message to APN(https://github.com/duccio/ApnsPHP) it arrives

"? Vei na boa vou dar um tiro nesse push"

Someone know how can I convert this?

@iamcal
Copy link
Owner

iamcal commented Apr 15, 2013

That's not how you escape UTF-8 in PHP. Try this:

"\xEE\x90\x95 Vei na..."

You can find the UTF-8 bytes for a codepoint using this: http:https://unicodey.com/?cp=e415

@iamcal iamcal closed this as completed Apr 15, 2013
@iamcal
Copy link
Owner

iamcal commented Apr 15, 2013

Oh, iPhones (since iOS) now use unified emoji, so you really want:

"\xF0\x9F\x98\x84 Vei na..."

Which is codepoint U+1F604

@phmarques
Copy link

Cal, can you explain it with more details, please?

@iamcal
Copy link
Owner

iamcal commented Apr 15, 2013

  1. How are you sending the message to APN? Using what language and what code?
  2. iOS no longer uses \ue415 - you should be using \u1f604

@alexleandrom
Copy link
Author

We try to send emoji from php webservice.
We using this Lib to send on php
https://github.com/duccio/ApnsPHP

@iamcal
Copy link
Owner

iamcal commented May 24, 2013

It looks like ApnsPHP does some special handling for Unicode. Try this:

$message->setText("Emoji: \\uD83D\\uDE04");

Apns expects 4-nibble \u escapes with a literal slash. To encode an emoji like U+1f604 you need to split it into two surrogate pair codepoints. I used the calculator here: http:https://www.russellcottrell.com/greek/utilities/SurrogatePairCalculator.htm

@vikmalhotra
Copy link

I am trying to send push notifications with emoji using php. For sending push notifications, I started with this tutorial and have got the push notifications working.
For sending emoji in push notifications from my php server, I tried with following code snippets, but all I keep getting in the notification is the Unicode characters as it is.

Here are some code snippets I tried...

$body['aps'] = array('alert' => '\xe2\x98\x81 Check', 'sound' => 'default');
$body['aps'] = array('alert' => emoji_unified_to_softbank('\xe2\x98\x81 Check'), 'sound' => 'default');
$body['aps'] = array('alert' => emoji_softbank_to_unified('\xe2\x98\x81 Check'), 'sound' => 'default');

What I should be getting here is a cloud emoji followed by the string 'Check'. But what I get is simply the string, \xe2\x98\x81 Check. I saw that the message looks like this in the payload (I am using json_encode to convert the payload that is a php array, to json encoded format):

\\xe2\\x98\\x81 Check

The reason could be that the payload has to be converted from php array to json-encoded format.
$payload = json_encode($body);

What am I doing wrong here? Can somebody help me out with this?

@alexleandrom
Copy link
Author

Hi dudu I try a lot of tutoriais, but the only step which works is change mysql encoding: Try this:
http:https://mathiasbynens.be/notes/mysql-utf8mb4

@vikmalhotra
Copy link

Hi alex, I did not make use of mysql anywhere. The emoji code is hard-coded into the payload in php code.

@iamcal
Copy link
Owner

iamcal commented Jun 18, 2013

vikkun: it all depends on the library doing the push notifications. Apple wants to recieve JSON looking like this:

"body" : "\u2601"

so try the following PHP:

$body['aps'] = array('alert' => '\\u2601');

@vikmalhotra
Copy link

iamcal: After referring your earlier comment, I am trying to use the unified emoji codes. But \\u2601 did not work either.
Here is my gist of what I am trying to do. It seems that since I am json encoding my payload, escaping the slash does not work.

// Create the payload body - emoji for smiling face with open mouth and smiling eyes
$body['aps'] = array('alert' => '\xf0\x9f\x98\x84', 'sound' => 'default');

// THIS IS WHAT SEEMS TO BE CAUSING THE EMOJI CODE TO APPEAR AS IT IS ON iPhone
$payload = json_encode($body);

Is there some workaround to this situation?

@iamcal
Copy link
Owner

iamcal commented Jun 19, 2013

It's as simple as using double quotes:

$body['aps'] = array('alert' => "\xf0\x9f\x98\x84", 'sound' => 'default');

After calling json_encode() on that, you'll get:

{"aps":{"alert":"\ud83d\ude04","sound":"default"}}

...which is correct JavaScript unicode escaping.

@ghost
Copy link

ghost commented Jun 17, 2015

Does emoji works with APNS Java code? If yes, could you please share code snippet ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants