iOS 5中的表情符号和UIWebView [英] Emoji and UIWebView in iOS 5

查看:180
本文介绍了iOS 5中的表情符号和UIWebView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到我的应用中的表情符号已停止在iOS 5中的UIWebView上正常显示。

I've noticed that emojis in my app have stopped displaying properly on a UIWebView in iOS 5.

所有字符在显示时都会针对HTML进行编码输出HTML是:

All characters are encoded for HTML when they are displayed and the output HTML is:

<p>Emoji (iOS 4): &#55357;&#56850;</p>

这个UTF-8编码的HTML在iOS 4的UIWebView中正确呈现,但不在5中:

This UTF-8 encoded HTML is rendered correctly in a UIWebView in iOS 4, but not in 5:

我知道iOS 5中有关于表情符号的一些变化,但表情符号字符已被编码为&#55357;&#56850;在iOS 5上生成,因此2字节字符应该是正确的。没有对代码进行任何其他更改,所以它肯定是iOS 5中引入的。

I understand there have been some changes in iOS 5 with regards to emoji, but the emoji character that has been encoded into &#55357;&#56850; was generated on iOS 5, so the 2 byte characters should be correct. No other changes have taken place to the code so it's definitely something introduced with iOS 5.

任何建议都将非常感谢,如果需要,我很乐意提供更多信息。谢谢。

Any advice would be much appreciated and I'll happily provide more information if required. Thanks.

推荐答案

我有一个来自开发人员论坛的回复


iOS 5和Safari 5.1中的HTML解析器已更改,0xD800..0xDFFF(55296..57343)范围内的字符引用被视为解析错误并生成对象替换字符(通常呈现为带问号的菱形)。行为的这种变化与HTML5指定的一致。这意味着您不能再使用代理项对字符引用对字符进行编码。

The HTML parser in iOS 5 and Safari 5.1 has changed, and character references in the range 0xD800..0xDFFF (55296..57343) are treated as parsing errors and produce an object replacement character (which is typically rendered as a diamond with a question mark). This change in behaviour is consistent with what HTML5 specifies. This means that you can no longer encode characters using surrogate pair character references.

一个相对简单的解决方案是使用单个字符引用而不是代理项对。在您的示例中,使用0x1F612而不是(0xD83D,0xDE12)。您可以使用十六进制或十进制:

A relatively simple solution is to use a single character reference instead of a surrogate pair. In your example, instead of (0xD83D, 0xDE12), use 0x1F612. You can use either hex or decimal:


&#x1f612;或&#128530;

&#x1f612; or &#128530;


这解释了问题的原因。然而,我通过仅编码较小的字符子集解决了这个问题,因为HTML文档是unicode。

This explains the reason for the problem. I however, worked around the issue by only encoding a smaller subset of characters as the HTML document is in unicode.

这篇关于iOS 5中的表情符号和UIWebView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆