how to convert the old emoji encoding to the lates

2019-04-07 23:26发布

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.

2条回答
放荡不羁爱自由
2楼-- · 2019-04-08 00:00

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? enter image description here

查看更多
祖国的老花朵
3楼-- · 2019-04-08 00:20

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.

查看更多
登录 后发表回答