iOS development--uitextview prohibit emoji input

Source: Internet
Author: User

Uitextview Proxy Method: Judging

-(void) textviewdidendediting: (Uitextview *) textview{
if ([self stringContainsEmoji:self.feedbackTextView.text]) {
Uialertview *alertview = [[Uialertview alloc] initwithtitle:@ "cannot have emoji, please enter Chinese" message:nil delegate:self cancelbuttontitle:@ "OK" otherbuttontitles:nil, nil];
[Alertview show];
}
}

#pragma mark determines whether the NSString string contains emoji expressions
-(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 <= 0XDBFF) {
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 <= 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 = = 0X303D | | hs = = 0X3030 | | hs = = 0X2B55 | | hs = 0X2B1C | | hs = 0X2B1B | | hs = = 0x2b50) {
returnvalue = YES;
}
}
}];

Return returnvalue;

}

iOS development--uitextview prohibit emoji input

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.