首页 > 代码库 > 禁止输入表情的方法

禁止输入表情的方法

static NSCharacterSet *_variationSelectors;
_variationSelectors = [NSCharacterSet characterSetWithRange:NSMakeRange(0xFE00, 16)];

 

- (BOOL)isEmoji:(NSString *)string{
if ([string rangeOfCharacterFromSet: _variationSelectors].location != NSNotFound) {
return YES;
}

const unichar high = [string characterAtIndex: 0];
// Surrogate pair (U+1D000-1F9FF)
if (0xD800 <= high && high <= 0xDBFF) {
const unichar low = [string characterAtIndex: 1];
const int codepoint = ((high - 0xD800) * 0x400) + (low - 0xDC00) + 0x10000;

return (0x1D000 <= codepoint && codepoint <= 0x1F9FF);

// Not surrogate pair (U+2100-27BF)
} else {
return (0x2100 <= high && high <= 0x27BF);
}
}

禁止输入表情的方法