Unicode character change after retrieving from server in iPhone - iphone

I have an iPhone application in which I am sending text in an UITextview to a server through a web service. and in the next page I am displaying the list of comments from the server through the web service. Everything is working fine except when I insert emoji/emoticons in the UITextview.
The next page displays square boxes instead of some emoji character (not all).
I have noticed that:
Working: I have inserted one emoji character in UITextview from an emoji keyboard and printed its code in log, \u2601, and submitted this text to the server. In the next page I got the same unicode \u2601 and it's working fine. It shows me the emoji icon.
Not Working: Now I have inserted another emoji character in the UITextview from the emoji keyboard and printed its code in log, \ud83d\udc16, and submitted this text to the server. In the next page I got a unicode codepoint which is different from what I sent: \uf416. iPhone doesn't recognize this unicode so it gives me a square box.
So what is the problem here? It's not working only when the emoji character has a pair of unicode codepoints.
The database in which the comment is stored is MySQL version 5.5.
Why does the emoji character code pair change when retrieved from the server? How to decode the retrieved Unicode into its original form so iPhone can recognize it?

The character U+F416 is in one of the Private Use Areas (PUA).
Likely, some code on the way from the app to the database and back replaced the emoji with this character. This could be any of the components on this way, e.g. the client library tha you use to communicate with the service, the web service, the database interface, or the database itself. Try to tackle each of this layers individually, or follow the character through the layers to check whether it is still correct.

Thanx Mar Byers, You gave me hint. I have read what is Unicode planes and what is surrogates and how it works. I have found that that is no server problem actually, because my SQL server version is 5.5 that has character set uyf8mb4, i have used that set in Comments column.
Now the problem with SBJSON that i used in my app to decode json response geting from server.SBJSON decode that surrogate pair(UTF16 UTF16) in one unicode UTF16, and thats why the emoji with surrogate pair is not displayed. Apple introduce json library NSJSONSerialization for ios5 and later os. I used that library to decode json response and my code work like charm..:)
I have got solution from here
http://blog.manbolo.com/2011/12/12/supporting-ios-5-new-emoji-encoding
and here
http://blog.manbolo.com/2012/10/29/supporting-new-emojis-on-ios-6
thanx to #Manbolo Blog.

Related

Support displaying emojis in UILabel

I'm having problems displaying emojis in a UILabel.
in some cases, it even causes a crash when lay-outing the characters in the label.
these characters are returning from server as unicode, and are parsed with AFNetworking framework.
this is an example of how it is returned from the server (console logs):
\U05d4\U05d9\U05d9
i have tried different approaches, like lowercasing this to "\u05d4" or playing with the encoding of the string returning.
nothing seems to work.
i did managed to show a couple of emojis properly (which makes me think it maybe a server related issue?) - does the server needs to support sets of unicode characters so it can return it in the appropriate encoding? i'd be happy if someone could clarify this point for me. (btw, server is written in RubyOnRails i believe.)
should i parse the data with a different parser (SBJSON)? although switching the networking framework at this point would be impossible due to time and resources available..
what other options do i have?
Thanks
i think you should be able to just paste an emoji character in the code directly as a text.

How to display emoji char in HTML

I saved the face "savouring delicious food emoji" to database, and read it in php json_encode which show "uD83D\uDE0B"。 but usually we use one <img /> label to replace it .
however,usually I just find this format '\uE056' not "uD83D\uDE0B",to replace with pic E056.png .
I don't know how to get the pic accroding to 'uD83D\uDE0B'.someone know ?
What the relation between 'uD83D\uDE0B' and '\uE056', they both represent emoji "savouring delicious food"?
The Unicode character U+1F60B FACE SAVOURING DELICIOUS FOOD is a so-called Plane 1 character, which means that its UTF-16 encoded form consists of two 16-bit code units, namely 0xD83D 0xDE0B. Generally, Plane 1 characters cause considerable problems because many programs are not prepared to deal with them, and few fonts contain them.
According to http://www.fileformat.info/info/unicode/char/1f60b/fontsupport.htm this particular character only exists in DejaVu fonts and in Symbola, but the versions of DejaVu I’m using don’t contain it.
Instead of dealing with the problems of encodings (which are not that difficult, but require extra information), you can use the character reference 😈 in HTML. But this does not solve the font problem. I don’t know about iPhone fonts, but in general in web browsing, the odds of a computer having any font capable of rendering the character are probably less than 1%. So you may need to use downloadable fonts. Using an image is obviously much simpler and mostly more reliable.
U+E056 is a Private Use codepoint, which means that anybody can make an agreement about its meaning with his brother or with himself, without asking anyone else’s mind. A font designer may assign any glyph to it.
IMPORTANT: As of this posting, the only browser that doesn't automatically support emojis is chrome.
FOR CHROME:
Depending on what server side language you are using, you should be able to find a library that converts emojis for you. I recently needed to solve this issue with php and used this library:
https://github.com/iamcal/php-emoji
The creator essentially created a sprite and adjusts the css according to the unicode of the emoji. It isnt pretty, but luckily he/she did all the grunt work for you. If you're using a different language you should be able to find something similar.
how do I put those little boxes into a php file?
Same way as any other Unicode character. Just paste them and make sure you're saving the PHP file and serving the PHP page as UTF-8.
When I put it into a php file, it turns into question marks and what not
Then you have an encoding problem. Work it out with Unicode characters you can actually see properly first, for example ąαд™日本, before worrying about the emoji.
Your PHP file should be saved as UTF-8; the page it produces should be served as Content-Type: text/html;charset:UTF-8 (or with similar meta tag); the MySQL database should be using a UTF-8 collation to store data and PHP should be talking to MySQL using UTF-8.
However. Even handling everything correctly like this, PCs will still not show the emoji. That's because:
they don't have fonts that include shapes for those characters, and
emoji are still completely unstandardised. Those characters you posted are in the Unicode Private Use Area, which means they don't have any official meaning at all.
Each network in Japan uses different character codes for their emoji, mapped to different areas in the PUA. So even on another mobile phone, it probably won't display the correct character, unless you spend ages manually converting emoji codes for different networks. I'm guessing the ones you posted above are from SoftBank (iPhone?).
There is an ongoing proposal led by Google and Apple to collate the different networks' emoji and give them a proper standardised place in Unicode. Until then, getting emoji to display consistently across networks is an exercise in unhappiness. See the character overview from the standardisation work to see how much converting you would have to do.
God, I hate emoji. All that pain for such a load of useless twee rubbish.

Character convert ion for Spanish characters in iPhone

I am writing an iPhone app, and I am consuming web services to get some info. This info is UTF-8 encoded, but some Spanish special characters are shown in a strange way (for instance, Ó is shown as Ó).
How could I convert them?
Thanks.
Check this solution ,it may help:
Spanish character encoding - iphone
Greetings from another spaniard!

UTF8 encoding problem, same results work fine in wordpress

I have a wordpress installation that clients can edit, all characters display ok. On the main homepage I query the same database for the same title and post content, but it doesn't display correctly - just a question mark
I have tried sending the utf8 headers manually, through htaccess and through meta tags. I have used SET name UTF8 (which turns the characters into the diamond symbol with a questionmark inside).
I genuinely cant figure out what it could be now and I really need these characters to display correctly.
Heres the homepage, you can see in the Sounddhism 6 preview that there are lots of question marks, if you click on it you will see what they are meant to look like
http://nottingham.subverb.net
I have passed it through the validator and it gives me this error:
Sorry, I am unable to validate this document because on line 373 it contained one or more bytes that I cannot interpret as utf-8 (in other words, the bytes found are not valid values in the specified Character Encoding). Please check both the content of the file and the character encoding indication.
The error was: utf8 "\xA0" does not map to Unicode
Which, i appreciate is supposed to help me, but I don't know what to do about it. Especially since that line, the letter generating the error is supposed to be a space and is AFTER the offending question marks.
Can anyone help?
Compare the encoding of both the back-end scripts in Wordpress and also your homepage script. If you're using IE, right-click the page and check the encoding. Sometimes it's set to "Auto-detect" and IE will often detect a different encoding for different pages, causing strange issues like this.
If you're not using IE, try using a tool like Fiddler to see exactly what encoding (and what bytes are being sent back and forth both in the back-end and your homepage script.
If forcing UTF-8 on your homepage script doesn't work, I would guess that the back-end is not using UTF-8.

French characters in SQLite..how to display properly in iPhone app?

I am working on an iPhone app using a SQLite db. I have some French characters that are not rendering properly in the app - they are being displayed as squares.
The character set client is: utf8. Is there an easy fix for this?
Check that everything is using UEF8, including the database, table and row. Try using some of the sample code with French characters.
You can use SQLiteManager to see how your database was created and whether it's using UTF8.
Actually, the font I was using did not render those characters correctly! Problem solved!
Check your fonts!