Uitextfield and Uitextview masked emoji input in iOS

Source: Internet
Author: User
<span id="Label3"></p><p><p>Cause: The cloud server code does not support emoji input, so the app side needs to block out all Uitextfield and uitextview masked emoji input</p></p><p><p>Solution: think of two solutions, one is to filter out after the input, the Internet to find some filtering algorithm, it seems to be not very good, and another block iOS input emoji Input. (the following solutions are not original, affixed to the record, but also to people who have the same problem to provide a little help it ^_^)</p></p><p><p>(1) take TextView as an example to add the following proxy method, the input of the expression is forbidden, [uitextinputmode currentinputmode] This method has been enabled after ios7, now in Xcode is only a warning but can use, instead of its method + (nsarray<nsstring *> *) activeinputmodes, did not find how to use, and will use to leave a message ha, Thank you very much!</p></p><p><p>-(BOOL) textView: (uitextview *) textView shouldchangetextinrange: (nsrange) range replacementtext: (nsstring *) text {</p></p><p><p><span style="line-height: 1.5;">If ([[[[uitextinputmode currentinputmode] primarylanguage] isequaltostring:@ "emoji"]) {</span></p></p><p><p>Return NO;</p></p><p><p>}</p></p><p><p>Return YES;</p></p><p><p>}</p></p><p><p>(2) in order to prevent user input haha, There is a smiley face hint, and thus entered the emoji, in the textviewdidendediting added to determine whether there is an expression input method, if there is a pop alert prompt to let the user Re-enter.</p></p><p><p>Using the algorithm in the http://blog.csdn.net/liujinlongxa/article/details/44207003, easy to use and effective, to prevent the code can not find, and then paste it again.</p></p><p><p>+ (BOOL) stringcontainsemoji: (nsstring *) string</p></p><p><p>{</p></p><p><p>__block BOOL returnvalue = NO;</p></p><p><p></p></p><p><p>[string enumeratesubstringsinrange:nsmakerange (0, [string length])</p></p><p><p>Options:nsstringenumerationbycomposedcharactersequences</p></p><p><p>usingblock:^ (nsstring *substring, nsrange substringrange, nsrange enclosingrange, BOOL *stop) {</p></p><p><p>Const UNICHAR HS = [substring characteratindex:0];</p></p><p><p>If (0xd800 <= HS && HS <= 0xdbff) {</p></p><p><p>If (substring.length > 1) {</p></p><p><p>Const Unichar ls = [substring characteratindex:1];</p></p><p><p>const int UC = ((HS-0XD800) * 0x400) + (ls-0xdc00) + 0x10000;</p></p><p><p>If (0x1d000 <= UC && UC <= 0x1f77f) {</p></p><p><p>returnvalue = YES;</p></p><p><p>}</p></p><p><p>}</p></p><p><p>} else if (substring.length > 1) {</p></p><p><p>Const Unichar ls = [substring characteratindex:1];</p></p><p><p>if (ls = = 0x20e3) {</p></p><p><p>returnvalue = YES;</p></p><p><p>}</p></p><p><p>} else {</p></p><p><p>If (0x2100 <= HS && HS <= 0x27ff) {</p></p><p><p>returnvalue = YES;</p></p><p><p>} else if (0x2b05 <= HS && HS <= 0x2b07) {</p></p><p><p>returnvalue = YES;</p></p><p><p>} else if (0x2934 <= HS && HS <= 0x2935) {</p></p><p><p>returnvalue = YES;</p></p><p><p>} else if (0x3297 <= HS && HS <= 0X3299) {</p></p><p><p>returnvalue = YES;</p></p><p><p>} else if (hs = = 0xa9 | | hs = = 0XAE | | hs = = 0X303D | | hs = = 0X3030 | | hs = = 0X2B55 | | hs = 0X2B1C | | hs = 0X2B1B | | hs = = 0x2b50) {</p></p><p><p>returnvalue = YES;</p></p><p><p>}</p></p><p><p>}</p></p><p><p>}];</p></p><p><p></p></p><p><p>Return returnvalue;</p></p><p><p>}</p></p><p><p>Uitextfield and Uitextview masked emoji input in iOS</p></p></span>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.