我怎样才能获得 Apple 表情符号名称而不是 Unicode 名称?
How could I get Apple emoji name instead of Unicode name?
我发现表情符号的 Unicode 名称与其在 Character Viewer 中显示的 Apple 名称不同。如何使用 Swift 获取表情符号的 Apple 名称?
示例:
表情符号:
Unicode 名称(通过 .applyingTransform(.toUnicodeName, reverse: false)
获得):
smiling face with open mouth and smiling eyes
Apple 名称(从 macOS Character Viewer 获取):
grinning face with squinting eyes
查看带有 Hoppper 的 Character Viewer 应用程序,似乎没有 API,但您可以使用 XCP 服务获取它。
+[CPKDefaultDataSource localizedCharacterName:]
的伪代码
/* @class CPKDefaultDataSource */
+(void *)localizedCharacterName:(void *)arg2 {
r14 = arg2;
rax = [CPKDefaultDataSource preferredEmojiLocale];
if (rax != 0x0) {
rax = CEMEmojiTokenCreateWithString(r14, rax);
if (rax != 0x0) {
r15 = CEMEmojiTokenCopyName(rax, 0x2);
CFRelease(rax);
if (r15 != 0x0) {
rax = [r15 autorelease];
}
else {
rax = [[CPSearchManager sharedSearchManager] infoForCharcater:r14 infoTag:@"unam"];
}
}
else {
rax = [[CPSearchManager sharedSearchManager] infoForCharcater:r14 infoTag:@"unam"];
}
}
else {
rax = 0x0;
}
return rax;
}
-[CPSearchManager infoForCharcater:infoTag:]
的前序代码
/* @class CPSearchManager */
-(void *)infoForCharcater:(void *)arg2 infoTag:(void *)arg3 {
...
rax = [CPCharacterDatabase sharedDatabase];
rax = [rax createXPCDictionaryForCharacterInfo:r14];
...
rax = [r12 cStringUsingEncoding:0x4];
rax = xpc_dictionary_get_value(r15, rax);
...
rax = xpc_dictionary_create(0x0, 0x0, 0x0);
r12 = rax;
xpc_dictionary_set_string(rax, "command", "search_character_info");
xpc_dictionary_set_string(r12, "string", [r14 cStringUsingEncoding:0x4]);
rdx = *(r15 + 0x10);
*(r15 + 0x10) = rdx + 0x1;
xpc_dictionary_set_uint64(r12, "transactionID", rdx + 0x1);
rax = _CPXPCConnection();
rax = xpc_connection_send_message_with_reply_sync(rax, r12);
rax = xpc_dictionary_get_value(rax, "result");
...
}
我在这个框架中找到了所有这些:/System/Library/PrivateFrameworks/CharacterPicker.framework
,如果你是为 macOS 构建这个,你可以link针对这个库进行私人分发
第一个是 Unicode 名称,但正确的名称是:
SMILING FACE WITH OPEN MOUTH AND SMILING EYES
大写很重要。它是一个 Unicode 标识符。它是永久的,它是独一无二的。 (它真的是永久的,即使他们在“PRESENTATION FORM FOR VERTICAL RIGHT WHITE LENTICULAR BRAKCET”中拼错了像“BRAKCET”这样的词,这个名字是永远的。
第二个名字是“Apple Name”。这些是本地化名称。在 Mac,英文版本存储在:
/System/Library/PrivateFrameworks/CoreEmoji.framework/Versions/A/Resources/en.lproj/AppleName.strings
您可以使用 plutil
转储此文件,或使用 PropertyListDecoder 读取它。
$ plutil -p AppleName.strings
{
"〰" => "wavy dash"
"‼️" => "red double exclamation mark"
"⁉️" => "red exclamation mark and question mark"
"*️⃣" => "keycap asterisk"
"#️⃣" => "number sign"
"〽️" => "part alternation mark"
"©" => "copyright sign"
...
也就是说,除非您绝对需要匹配 Apple,否则我建议使用 CLDR(通用语言环境数据存储库)注释短名称。这是本地化名称的 Unicode 源代码。不过,它们并没有承诺是独一无二的。他们最大的目的就是支持text-to-speech.
对于 XML 中的当前列表,在 GitHub. Or you can browse the v37 table or download the raw data 上最方便。
我发现表情符号的 Unicode 名称与其在 Character Viewer 中显示的 Apple 名称不同。如何使用 Swift 获取表情符号的 Apple 名称?
示例:
表情符号:
Unicode 名称(通过 .applyingTransform(.toUnicodeName, reverse: false)
获得):
smiling face with open mouth and smiling eyes
Apple 名称(从 macOS Character Viewer 获取):
grinning face with squinting eyes
查看带有 Hoppper 的 Character Viewer 应用程序,似乎没有 API,但您可以使用 XCP 服务获取它。
+[CPKDefaultDataSource localizedCharacterName:]
的伪代码/* @class CPKDefaultDataSource */
+(void *)localizedCharacterName:(void *)arg2 {
r14 = arg2;
rax = [CPKDefaultDataSource preferredEmojiLocale];
if (rax != 0x0) {
rax = CEMEmojiTokenCreateWithString(r14, rax);
if (rax != 0x0) {
r15 = CEMEmojiTokenCopyName(rax, 0x2);
CFRelease(rax);
if (r15 != 0x0) {
rax = [r15 autorelease];
}
else {
rax = [[CPSearchManager sharedSearchManager] infoForCharcater:r14 infoTag:@"unam"];
}
}
else {
rax = [[CPSearchManager sharedSearchManager] infoForCharcater:r14 infoTag:@"unam"];
}
}
else {
rax = 0x0;
}
return rax;
}
-[CPSearchManager infoForCharcater:infoTag:]
的前序代码/* @class CPSearchManager */
-(void *)infoForCharcater:(void *)arg2 infoTag:(void *)arg3 {
...
rax = [CPCharacterDatabase sharedDatabase];
rax = [rax createXPCDictionaryForCharacterInfo:r14];
...
rax = [r12 cStringUsingEncoding:0x4];
rax = xpc_dictionary_get_value(r15, rax);
...
rax = xpc_dictionary_create(0x0, 0x0, 0x0);
r12 = rax;
xpc_dictionary_set_string(rax, "command", "search_character_info");
xpc_dictionary_set_string(r12, "string", [r14 cStringUsingEncoding:0x4]);
rdx = *(r15 + 0x10);
*(r15 + 0x10) = rdx + 0x1;
xpc_dictionary_set_uint64(r12, "transactionID", rdx + 0x1);
rax = _CPXPCConnection();
rax = xpc_connection_send_message_with_reply_sync(rax, r12);
rax = xpc_dictionary_get_value(rax, "result");
...
}
我在这个框架中找到了所有这些:/System/Library/PrivateFrameworks/CharacterPicker.framework
,如果你是为 macOS 构建这个,你可以link针对这个库进行私人分发
第一个是 Unicode 名称,但正确的名称是:
SMILING FACE WITH OPEN MOUTH AND SMILING EYES
大写很重要。它是一个 Unicode 标识符。它是永久的,它是独一无二的。 (它真的是永久的,即使他们在“PRESENTATION FORM FOR VERTICAL RIGHT WHITE LENTICULAR BRAKCET”中拼错了像“BRAKCET”这样的词,这个名字是永远的。
第二个名字是“Apple Name”。这些是本地化名称。在 Mac,英文版本存储在:
/System/Library/PrivateFrameworks/CoreEmoji.framework/Versions/A/Resources/en.lproj/AppleName.strings
您可以使用 plutil
转储此文件,或使用 PropertyListDecoder 读取它。
$ plutil -p AppleName.strings
{
"〰" => "wavy dash"
"‼️" => "red double exclamation mark"
"⁉️" => "red exclamation mark and question mark"
"*️⃣" => "keycap asterisk"
"#️⃣" => "number sign"
"〽️" => "part alternation mark"
"©" => "copyright sign"
...
也就是说,除非您绝对需要匹配 Apple,否则我建议使用 CLDR(通用语言环境数据存储库)注释短名称。这是本地化名称的 Unicode 源代码。不过,它们并没有承诺是独一无二的。他们最大的目的就是支持text-to-speech.
对于 XML 中的当前列表,在 GitHub. Or you can browse the v37 table or download the raw data 上最方便。