- 7
- 0
- 约1.67千字
- 约 3页
- 2021-11-14 发布于江苏
- 举报
iOS 禁止输入 emoji 表情
因为 emoji 编码在 android 或者 pc 设备没有很好的支持,所以有时候为了禁止 emoji 表情的输入,因为关闭不了系统 emoji 的键盘,那只能根据编码把 emoji 表情过滤掉,写了一个NSString 的拓展,用来判断是不是 emoji 编码:
@implementation NSString(Emoji)
+(BOOL)isContainsEmoji:(NSString *)string {
block BOOL isEomji = NO;
[string enumerateSubstringsInRange:NSMakeRange(0,
[string length]) options:NSStringEnumerationByComposedCharacterSequencesusi ngBlock:
^(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop) {
const unichar hs = [substring characterAtIndex:0];
// surrogate pair
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) {
isEomji = YES;
}
}
} else if (substring.length 1) {
const unichar ls = [substring characterAtIndex:1]; if (ls == 0x20e3) {
isEomji = YES;
}
} else {
// non surrogate
if (0x2100 = hs hs = 0x27ff hs != 0x263b) { isEomji = YES;
} else if (0x2B05 = hs hs = 0x2b07) { isEomji = YES;
} else if (0x2934 = hs hs = 0x2935) { isEomji = YES;
} else if (0x3297 = hs hs = 0x3299) { isEomji = YES;
} else if (hs == 0xa9 || hs == 0xae || hs == 0x303d || hs
== 0x3030 || hs == 0x2b55 || hs == 0x2b1c || hs == 0x2b1b || hs == 0x2b50|| hs == 0x231a ) {
isEomji = YES;
}
}
}];
return isEomji;
}
这样在 textview 或 textfield的 delegate 判断一下,即可禁止输入 emoji ,如下:
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
//emoji 无效
if([NSString isContainsEmoji:string])
{
return NO;
}
}
当然,最好的方法还是做一套 emoji 的编码解码,以支持其他非 ios 设备。不然禁止这个功能有点说不过去。
您可能关注的文档
- IDC项目建设中的难点及解决方案V2.pdf
- IDC项目是指什么?.pdf
- IDL程序设计开发.pdf
- ie、üe、er 第二课时教案教学设计.pdf
- IECQ-QC080000:2017有害物质过程管理体系文件.pdf
- IE动作分析培训课件.pdf
- ifix系统数据库添加说明.pdf
- IGK街道一幼大班数学教案-大班数学《5的组成》.pdf
- Ifix软件培训教程.pdf
- IGP区第二幼儿园中班美术教案-蝴蝶飞来了.pdf
- 山西天一大联考2025-2026学年高二上学期期末学情监测语文试题(试卷+解析).docx
- 山西忻州部分学校2025-2026学年高一上学期2月质量检测数学试题(人教B版)(试卷+解析).docx
- 山西运城市2025-2026学年高二第一学期期末调研测试数学试题(试卷+解析).docx
- 陕西省榆林市榆阳区2025-2026学年八年级上学期期末地理试题(试卷+解析).docx
- 陕西西安市碑林区2025-2026学年度第一学期期末八年级生物试题(试卷+解析).docx
- 四川省广元市苍溪县2025-2026年八年级上学期期末道德与法治试题(试卷+解析).docx
- 江苏泰州市姜堰区2025-2026学年七年级上学期1月期末数学试题(试卷+解析).docx
- 江苏省扬州市邗江区2025-2026学年九年级上学期期末考试化学试题(试卷+解析).docx
- 江西上饶市铅山县2025-2026学年第一学期期末考试八年级数学试题(试卷+解析).docx
- 江苏扬州市高邮市2025-2026学年度第一学期期末学业质量监测试题九年级英语(试卷+解析).docx
原创力文档

文档评论(0)