首页 > 解决方案 > iOS12 中文键盘(zh-Hans 和 zh-Hant)导致应用崩溃(TextFiled in UISearchBar/UIAlertView/UIAlertViewController)

问题描述

我的应用升级到 iOS 12 后出现此问题。每当调用原生中文键盘或第三方中文键盘时,应用都会崩溃。中文手写键盘不会导致死机。

该应用程序已本地化为英文和中文,因此 UserDefaults 中的“AppleLanguages”会根据用户修改不时更改。

用于 searchBar 的代码很简单。

@IBOutlet weak var searchBar: UISearchBar!
self.searchBar.delegate = self

异常消息是:

-[NSNull isSecureContentCandidate]: unrecognized selector sent to instance 0x1e39f99a0 * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSNull isSecureContentCandidate]: unrecognized selector sent to instance 0x1e39f99a0' * First throw call stack: (0x1b3ce3ef8 0x1b2eb1a40 0x1b3bfb154 0x1b3ce9810 0x1b3ceb4bc 0x1e030ed18 0x1e039472c 0x1e0394380 0x1e03e7030 0x1e0394330 0x1e03e9064 0x1e03e7774 0x1e03e7784 0x1b47935a0 0x1b3c725b8 0x1b3c72538 0x1b3c71e1c 0x1b3c6cce8 0x1b3c6c5b8 0x1b5ee0584 0x1e0567558 0x100575d34 0x1b372cb94) libc++abi.dylib: terminating with uncaught exception of type NSException

我试图通过强制应用程序使用字母键盘来解决崩溃问题,这会禁用出现此问题的页面的中文输入。

self.searchBar.keyboardType = UIKeyboardType.alphabet

先谢谢啦~!

标签: swiftuisearchbartextfielduialertviewios12

解决方案


通过调整本地 NSNull 扩展来修复崩溃。


推荐阅读