判断ios11新增的56种emoji表情

ios11新增了56种emoji表情,对应如下:

0x1f3f4

0x1f6f7

0x1f6f8

0x1f91(f)
0x1f92(8,9,a,b,c,d,e,f)

0x1f93(1,2)

0x1f94(c)

0x1f95(f)
0x1f96(0,1,2,3,4,5,6,7,8,9,a,b)
0x1f99(2,3,4,5,6,7)

0x1f9e(0,1,2,3,4,5,6)

0x1f9d(0,1,2,3,4,5,6,7,8,9,a,b,c,d,e)

原来的emoji表情判断基本使用下面的方式:

+ (BOOL)stringContainsEmoji:(NSString *)string

{

    BOOL returnValue = NO;

    if (!JDUtils.validateString(string)) {

        return returnValue;

    }

    const unichar hs = [string characterAtIndex:0];

    if (0xd800 <= hs && hs <= 0xdbff) {

        if (string.length > 1) {

            const unichar ls = [string characterAtIndex:1];

            const int uc = ((hs - 0xd800) * 0x400) + (ls - 0xdc00) + 0x10000;

            if (0x1d000 <= uc && uc <= 0x1f77f) {

                returnValue = YES;

            }

        }

    } else if (string.length > 1) {

        const unichar ls = [string 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;

}

原来的判断:

 if (0x1d000 <= uc && uc <= 0x1f77f) {

    returnValue = YES;

}

只包含:0x1f3f4、0x1f6f7、0x1f6f8

只需要把0x1f9的几种加入判断种就行了。

posted on 2017-12-28 18:25  流浪的虫子  阅读(311)  评论(0)    收藏  举报

导航