The emoji expression problem in IOS is judged _ios

Source: Internet
Author: User

Let's give you a description of the problem.

The server side does not support emoji expressions, so the client cannot include emoji expressions when uploading user input.

Solution

Before the client sends the request, determines whether the user input contains an expression and, if it contains an expression, prompts the user to re-enter it. The key to this process is to determine whether the string contains emoji expressions. To determine whether a emoji expression is included, you must first understand what is emoji.

Emoji is a set of 12x12 pixel emoticons that originated in Japan, created by Li Tanaka (Shigetaka Kurit), which was first popular among Japanese internet and mobile subscribers, which began to sweep around the world since Apple's iOS 5 Input method was added to the emoji. Emoji has been adopted by most modern computer systems compatible with Unicode encoding, and is widely used in all kinds of mobile phone messages and social networks.

Above is an excerpt from Baidu Encyclopedia, emoji expression will eventually be encoded into Unicode, so as long as you know emoji expression of the range of Unicode encoding, you can determine whether the user entered the emoji expression. Here is the specific code, I wrote here a classification of NSString

@implementation NSString (emoji) + (BOOL) Stringcontainsemoji: (NSString *) string {__block BOOL returnvalue = NO; [String Enumeratesubstringsinrange:nsmakerange (0, [string length]) options: Nsstringenumerationbycomposedcharactersequences usingblock:^ (NSString *substring, NSRange SubstringRange, NSRange Enclosingrange, BOOL *stop) {Const UNICHAR HS = [substring characteratindex:0]; if (0xd800 <= HS && HS <= 0  XDBFF) {if (Substring.length > 1) {const UNICHAR ls = [substring characteratindex:1]; const int UC = ((hs-0xd800) *
0x400) + (LS-0XDC00) + 0x10000;
if (0x1d000 <= UC && UC <= 0x1f77f) {returnvalue = YES;}}  else if (Substring.length > 1) {const UNICHAR ls = [substring characteratindex:1]; if (ls = = 0x20e3) {returnvalue =
YES; } else {if (0x2100 <= HS && HS <= 0x27ff) {returnvalue = YES;} else if (0x2b05 <= HS && HS &
lt;= 0x2b07) {returnvalue = YES;} else if (0x2934 <= HS && HS <= 0x2935) {returnvalue = YES; else if (0x3297 <= HS && HS <= 0x3299) {returnvalue = YES;} else if (hs = 0xa9 | | hs = 0XAE | | hs = = 0 x303d | | HS = = 0x3030 | | HS = = 0x2b55 | | HS = = 0x2b1c | | HS = = 0x2b1b | |
HS = = 0X2B50) {returnvalue = YES;}}
}];
Return returnvalue; }

This Code Pro test works, welcome you to refer to.

The above is a small set of iOS to introduce you to judge emoji expression problem, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.