美文网首页
iOS 10 -- 判断是否为表情

iOS 10 -- 判断是否为表情

作者: GOOGxu | 来源:发表于2017-03-14 13:27 被阅读0次

/** 是不是表情 */

- (BOOL)stringContainsEmoji

{

__block BOOL returnValue = NO;

// 不知道是什么原因,九宫格的时候,输入的是表情.但是其实是正常的输入.

if ([BTSpeedDialSTR rangeOfString:self].length > 0) {

return NO;

}

[self enumerateSubstringsInRange:NSMakeRange(0, [self length])

options:NSStringEnumerationByComposedCharacterSequences

usingBlock:^(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop) {

const unichar high = [substring characterAtIndex: 0];

// Surrogate pair (U+1D000-1F9FF)

if (0xD800 <= high && high <= 0xDBFF) {

const unichar low = [substring characterAtIndex: 1];

const int codepoint = ((high - 0xD800) * 0x400) + (low - 0xDC00) + 0x10000;

if (0x1D000 <= codepoint && codepoint <= 0x1F9FF){

returnValue = YES;

}

// Not surrogate pair (U+2100-27BF)

} else {

if (0x2100 <= high && high <= 0x27BF){

returnValue = YES;

}

}

}];

return returnValue;

}

相关文章

网友评论

      本文标题:iOS 10 -- 判断是否为表情

      本文链接:https://www.haomeiwen.com/subject/ezzcnttx.html