Emoji 的编码方式在 UTF8 之外,如果服务端不支持的话就 GG 了,如果暂时无法支持,只能屏蔽用户的输入了,下面这些范围在 iOS 10 上测试,99.99% 的表情都无法输入,别问我那 0.01%是哪个表情,因为我还没有测试全。O(∩_∩)O
extension String {
var containsEmoji: Bool {
for scalar in unicodeScalars {
switch scalar.value {
case 0x1F600...0x1F64F, // Emoticons
0x1F300...0x1F5FF, // Misc Symbols and Pictographs
0x1F680...0x1F6FF, // Transport and Map
0x2600...0x26FF, // Misc symbols
0x2700...0x27BF, // Dingbats
0xFE00...0xFE0F, // Variation Selectors
0x1F900...0x1F9FF: // Supplemental Symbols and Pictographs
return true
default:
continue
}
}
return false
}
}
网友评论