Javascript -[UIAlertController addTextFieldWithConfigurationHandler:]中的断言失败
在WKWebView内的JavaScript中调用Javascript -[UIAlertController addTextFieldWithConfigurationHandler:]中的断言失败,javascript,ios,swift,wkwebview,wkuidelegate,Javascript,Ios,Swift,Wkwebview,Wkuidelegate,在WKWebView内的JavaScript中调用窗口。提示符,会生成断言错误: -[UIAlertController]中的断言失败 addTextFieldWithConfigurationHandler:] 断言错误来自此WKUIDelegate函数: func webView(_ webView: WKWebView, runJavaScriptTextInputPanelWithPrompt prompt: String, defaultText: String?, initiated
窗口。提示符
,会生成断言错误:
-[UIAlertController]中的断言失败
addTextFieldWithConfigurationHandler:]
断言错误来自此WKUIDelegate函数:
func webView(_ webView: WKWebView, runJavaScriptTextInputPanelWithPrompt prompt: String, defaultText: String?, initiatedByFrame frame: WKFrameInfo,
completionHandler: @escaping (String?) -> Void) {
let alertController = UIAlertController(title: nil, message: prompt, preferredStyle: .actionSheet)
alertController.addTextField { (textField) in
textField.text = defaultText
}
alertController.addAction(UIAlertAction(title: "OK", style: .default, handler: { (action) in
if let text = alertController.textFields?.first?.text {
completionHandler(text)
} else {
completionHandler(defaultText)
}
}))
alertController.addAction(UIAlertAction(title: "Cancel", style: .default, handler: { (action) in
completionHandler(nil)
}))
present(alertController, animated: true, completion: nil)
}
类文档没有显示在添加文本字段或初始值设定项时添加配置处理程序的方法。那么您应该如何处理这个问题呢?尝试将样式
操作表更改为警报。对于将从UIAlertControllerStyleActionSheet
更改为UIAlertControllerStyleAlert
的Objective-C用户,应从viewController调用Present。怀疑您可能就是这种情况。在调用present
之前,在配置警报控制器时似乎发生了断言。您能否举出一个在尝试呈现警报时发生此断言失败的示例?