how to convert the old emoji encoding to the lates

2019-04-08 00:12发布

问题:

sadly, after iOS5 finally released, I got report from my users that they can not login.

Because there is emoji symbol in there names, and apple changed the encoding of emoji.

so there username contains a old version of emoji, how could I convert them to the new encoding?

thanks!

be specific: one emoji symbol "tiger", it is "\U0001f42f" in iOS5, but "\ue050" in earlier iOS version.

回答1:

iOS 5 and OS X 10.7 (Lion) use the Unicode 6.0 standard ‘unified’ code points for emoji.

iOS 4 on SoftBank iPhones used a set of unofficial code points in the Unicode Private Use Area, and so aren't compatible with any other systems. To convert from this format to proper Unicode 6.0 characters, you'll need to run a big lookup table from Softbank code to Unified over all your current data and all new form data as it gets submitted. You might also want to do Unicode normalisation at this point, so that eg. fullwidth letters match normal ASCII letters.

See for example this table from a library that does emoji conversion tasks for PHP.

Emoji in usernames though?



回答2:

I had the same problem, after digging for hours and finally found this answer that works for me

If you are using rails as your server, this is all you need to do. No need to do anything in ios/xcode, just pass the NSString without doing any UTF8/16 encoding stuff to the server.

Postegre stores the code correctly, it's just when you send the json response back to your ios client, assuming you do render json:@message, the json encoding has problem.

you could test whether you are having json encoding problem in your rails console by doing as simple test in your console test = {"smiley"=>"u{1f604}"} test.to_json

if it prints out "{\"smiley\":\"\uf604\"}" (notice the 1 is lost), then you have this problem. and the patch from the link will fix it.