iOS 5:如何将表情符号转换为unicode字符?

时间:2021-10-02 20:19:17

I want to convert an Emoji to a unicode character in iOS 5.

我想把一个表情符号转换成ios5中的unicode字符。

For example, converting iOS 5:如何将表情符号转换为unicode字符? to \ue415.

例如,转换为\ue415。

I went to NSStringEncoding in NSString Class Reference.

我使用NSString类引用的NSStringEncoding。

In iOS 4, NSUTF16BigEndianStringEncoding and NSUTF32BigEndianStringEncoding gave me <e415> and <0000e415>, respectively, which are quite close to what I want.

在ios4中,NSUTF16BigEndianStringEncoding和NSUTF32BigEndianStringEncoding分别给了我 和<0000e415>,这两种编码非常接近我想要的。

In iOS 5, the results are different. It gaves <d83dde04> and <0001f604>.

在ios5中,结果是不同的。它gaves 和<0001f604>。

How can I get \ue415 for iOS 5:如何将表情符号转换为unicode字符? in iOS 5? Thank you.

我如何在ios5中得到\ue415 ?谢谢你!

6 个解决方案

#1


14  

\ue415 is part of the legacy encoding for emoji and is specific to certain Japanese carriers. SoftBank, NTT and docomo all had their own private emoji character sets.

ue415是表情符号的一部分,是特定于某些日本运营商的。软银、NTT和docomo都有自己的私人表情符号。

iOS 5 has moved to the newly specified Unicode 6.0 support for emoji character planes and <0001f604> is the Unicode code point for that character. The wikipedia entry about this references an EmojiSources.txt mapping file that you'll need to use to do the mapping yourself if you really need to get the old private-use character codes.

ios5已经移动到新指定的Unicode 6.0支持表情字符,而<0001f604>是该字符的Unicode编码点。*上关于这一点的条目是一个表情符号。如果你真的需要得到旧的私有字符代码,你需要使用txt映射文件来完成映射。

http://en.wikipedia.org/wiki/Emoji

http://en.wikipedia.org/wiki/Emoji

#2


90  

Please try this :

请试试这个:

  1. Convert Emoji to unicode

    Emoji转换为unicode

    NSData *data = [strEmo dataUsingEncoding:NSNonLossyASCIIStringEncoding];
    NSString *goodValue = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
    
  2. Very easy to convert unicode to Emoji

    很容易将unicode转换成表情符号。

    NSData *data = [strEmo dataUsingEncoding:NSUTF8StringEncoding];
    NSString *goodValue = [[NSString alloc] initWithData:data encoding:NSNonLossyASCIIStringEncoding]; 
    

#3


7  

Convert back to:--

转换回:—

NSData *newdata=[recievedstring dataUsingEncoding:NSUTF8StringEncoding 
allowLossyConversion:YES];
    NSString *mystring=[[NSString alloc] initWithData:newdata encoding:NSNonLossyASCIIStringEncoding];

#4


7  

dispalying emoji in UILabel:

显示在UILabel emoji:

NSString *bellEmojiString = @"U+1F514";

label.text = [NSSting stringWithFormat:@"Table: %@", @"\U0001F514"];

you should be careful replace + with 3 zero digit

你应该小心地用3个零位代替+。

#5


6  

try this : http://opensource.apple.com/source/ICU/ICU-461.13/icuSources/data/translit/Any_SoftbankSMS.txt

试试这个:http://opensource.apple.com/source/icu/icu - 461.13 / - icusources/data/translit/any_softbanksms.txt

on iOS5, use left code, on iOS 4 and below, use the right code.

在iOS5上,使用左代码,在ios4和下面,使用正确的代码。

#6


4  

if your emoji doesn't take a round trip (from ios to a backend server and back to ios), then you shouldn't have any problem ios (at least 4.2+) handles the encoding correctly and you don't have to do anything. but if your app interact with a server, have you suspect that your server return value is wrong? i.e. json encoded wrong.

如果你的表情符号不需要往返(从ios到后台服务器再返回到ios),那么你就不应该有任何问题ios(至少4.2+)正确地处理编码,你不需要做任何事情。但是,如果您的应用程序与服务器交互,您是否怀疑您的服务器返回值是错误的?例如json编码的错误。

I had the same problem, after digging for hours and finally found this answer that works for me: https://*.com/a/8339255/1090945

在挖掘了几个小时后,我终于找到了适合我的答案:https://*.com/a/8339255/1090945。

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.

如果您使用rails作为您的服务器,这就是您所需要做的。不需要在ios/xcode中做任何事情,只需传递NSString,而不需要对服务器进行任何UTF8/16编码。

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.

Postegre正确地存储代码,当您将json响应发送回您的ios客户端时,假设您确实呈现json:@message, json编码有问题。

you could test whether you are having json encoding problem in your rails console by doing as simple test in your console

您可以通过在您的控制台中做简单的测试来测试您的rails控制台是否存在json编码问题。

test = {"smiley"=>"u{1f604}"} 

test.to_json

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.

如果它打印了“{\”smiley\“:\”\uf604\“}”(注意1丢失),那么您就有了这个问题。链接上的补丁会修复它。

#1


14  

\ue415 is part of the legacy encoding for emoji and is specific to certain Japanese carriers. SoftBank, NTT and docomo all had their own private emoji character sets.

ue415是表情符号的一部分,是特定于某些日本运营商的。软银、NTT和docomo都有自己的私人表情符号。

iOS 5 has moved to the newly specified Unicode 6.0 support for emoji character planes and <0001f604> is the Unicode code point for that character. The wikipedia entry about this references an EmojiSources.txt mapping file that you'll need to use to do the mapping yourself if you really need to get the old private-use character codes.

ios5已经移动到新指定的Unicode 6.0支持表情字符,而<0001f604>是该字符的Unicode编码点。*上关于这一点的条目是一个表情符号。如果你真的需要得到旧的私有字符代码,你需要使用txt映射文件来完成映射。

http://en.wikipedia.org/wiki/Emoji

http://en.wikipedia.org/wiki/Emoji

#2


90  

Please try this :

请试试这个:

  1. Convert Emoji to unicode

    Emoji转换为unicode

    NSData *data = [strEmo dataUsingEncoding:NSNonLossyASCIIStringEncoding];
    NSString *goodValue = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
    
  2. Very easy to convert unicode to Emoji

    很容易将unicode转换成表情符号。

    NSData *data = [strEmo dataUsingEncoding:NSUTF8StringEncoding];
    NSString *goodValue = [[NSString alloc] initWithData:data encoding:NSNonLossyASCIIStringEncoding]; 
    

#3


7  

Convert back to:--

转换回:—

NSData *newdata=[recievedstring dataUsingEncoding:NSUTF8StringEncoding 
allowLossyConversion:YES];
    NSString *mystring=[[NSString alloc] initWithData:newdata encoding:NSNonLossyASCIIStringEncoding];

#4


7  

dispalying emoji in UILabel:

显示在UILabel emoji:

NSString *bellEmojiString = @"U+1F514";

label.text = [NSSting stringWithFormat:@"Table: %@", @"\U0001F514"];

you should be careful replace + with 3 zero digit

你应该小心地用3个零位代替+。

#5


6  

try this : http://opensource.apple.com/source/ICU/ICU-461.13/icuSources/data/translit/Any_SoftbankSMS.txt

试试这个:http://opensource.apple.com/source/icu/icu - 461.13 / - icusources/data/translit/any_softbanksms.txt

on iOS5, use left code, on iOS 4 and below, use the right code.

在iOS5上,使用左代码,在ios4和下面,使用正确的代码。

#6


4  

if your emoji doesn't take a round trip (from ios to a backend server and back to ios), then you shouldn't have any problem ios (at least 4.2+) handles the encoding correctly and you don't have to do anything. but if your app interact with a server, have you suspect that your server return value is wrong? i.e. json encoded wrong.

如果你的表情符号不需要往返(从ios到后台服务器再返回到ios),那么你就不应该有任何问题ios(至少4.2+)正确地处理编码,你不需要做任何事情。但是,如果您的应用程序与服务器交互,您是否怀疑您的服务器返回值是错误的?例如json编码的错误。

I had the same problem, after digging for hours and finally found this answer that works for me: https://*.com/a/8339255/1090945

在挖掘了几个小时后,我终于找到了适合我的答案:https://*.com/a/8339255/1090945。

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.

如果您使用rails作为您的服务器,这就是您所需要做的。不需要在ios/xcode中做任何事情,只需传递NSString,而不需要对服务器进行任何UTF8/16编码。

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.

Postegre正确地存储代码,当您将json响应发送回您的ios客户端时,假设您确实呈现json:@message, json编码有问题。

you could test whether you are having json encoding problem in your rails console by doing as simple test in your console

您可以通过在您的控制台中做简单的测试来测试您的rails控制台是否存在json编码问题。

test = {"smiley"=>"u{1f604}"} 

test.to_json

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.

如果它打印了“{\”smiley\“:\”\uf604\“}”(注意1丢失),那么您就有了这个问题。链接上的补丁会修复它。