iOS5中如何将旧的emoji编码转换为最新的编码?
遗憾的是,在 iOS5 最终发布后,我收到用户的报告称他们无法登录。
因为名字里有emoji符号,苹果改变了emoji的编码。
那么用户名包含旧版本的表情符号,我如何将它们转换为新的编码?
谢谢!
具体来说:一个表情符号“老虎”,在iOS5中是“\U0001f42f”,而在早期的iOS版本中是“\ue050”。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
iOS 5 和 OS X 10.7 (Lion) 使用 Unicode 6.0 标准“统一”表情符号代码点。
SoftBank iPhone 上的 iOS 4 使用 Unicode 专用区域中的一组非官方代码点,因此与任何其他系统都不兼容。要从此格式转换为正确的 Unicode 6.0 字符,您需要在提交时对所有当前数据和所有新表单数据运行从 Softbank 代码到 Unified 的大型查找表。此时您可能还想进行 Unicode 标准化,例如。全角字母与普通 ASCII 字母匹配。
例如,请参阅为 PHP 执行表情符号转换任务的库中的此表。
用户名中的表情符号?
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?
我遇到了同样的问题,经过几个小时的挖掘,终于找到了这个答案对我有用
如果你使用rails作为你的服务器,这就是您需要做的。无需在 ios/xcode 中执行任何操作,只需传递 NSString 即可,无需向服务器执行任何 UTF8/16 编码操作。
Postegre正确存储代码,只是当您将json响应发送回ios客户端时,假设您渲染json:@message,json编码有问题。
您可以通过在控制台中执行简单的测试来测试 Rails 控制台中是否存在 json 编码问题
测试 = {“笑脸”=>“u{1f604}”}
test.to_json
如果打印出 "{\"smiley\":\"\uf604\"}" (注意 1 丢失了),那么你就会遇到这个问题。并且链接中的补丁将修复它。
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.