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