不支持输入系统表情符号
[[[textView textInputMode] primaryLanguage] isEqualToString:@"emoji"]
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
//不支持系统表情的输入
if ([[[UITextInputMode currentInputMode] primaryLanguage] isEqualToString:@"emoji"]) {
return NO;
}
return YES;
}
//过滤表情
(NSString *)filterEmoji:(NSString *)string {
NSUInteger len = [string lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
const char *utf8 = [string UTF8String];
char *newUTF8 = malloc( sizeof(char) * len );
int j = 0;
//0xF0(4) 0xE2(3) 0xE3(3) 0xC2(2) 0x30---0x39(4)
for ( int i = 0; i < len; i ) {
unsigned int c = utf8;
BOOL isControlChar = NO;
if ( c == 4294967280 ||
c == 4294967089 ||
c == 4294967090 ||
c == 4294967091 ||
c == 4294967092 ||
c == 4294967093 ||
c == 4294967094 ||
c == 4294967095 ||
c == 4294967096 ||
c == 4294967097 ||
c == 4294967088 ) {
i = i 3;
isControlChar = YES;
}
if ( c == 4294967266 || c == 4294967267 ) {
i = i 2;
isControlChar = YES;
}
if ( c == 4294967234 ) {
i = i 1;
isControlChar = YES;
}
if ( !isControlChar ) {
newUTF8[j] = utf8;
j ;
}
}
newUTF8[j] = '