【发布时间】:2017-02-28 15:33:02
【问题描述】:
背景和简短摘要
我正在使用 WkWebview 来显示我的应用程序的网页。我有它,以便您可以从相机或照片库中选择图像。但是,应用程序在选择图像时崩溃似乎存在问题。
规格
我在 Tablet 上的 IOS 10.0.2 和使用 Swift 3 的模拟器上的 IOS 10.0 上运行。我都在 XCode 8 上运行。
在模拟器上尝试上传图片时出现“错误”
我收到以下消息:
2016-10-19 02:15:36.150670 z4[31561:14708540] [Generic]
Creating an image format with an unknown type is an error
图片很好,我可以用它来上传。我认为这种行为很奇怪,但我读到它与 IOS 上的内存管理有关
在平板电脑上,我得到以下信息
Terminating app due to uncaught exception 'NSGenericException',
reason: 'Your application has presented a
UIAlertController (<UIAlertController: 0x151e80350>)
of style UIAlertControllerStyleActionSheet.
The modalPresentationStyle of a UIAlertController
with this style is UIModalPresentationPopover.
You must provide location information for this
popover through the alert controller's popoverPresentationController.
You must provide either a sourceView and sourceRect or a barButtonItem.
If this information is not known when you present the alert controller,
you may provide it in the UIPopoverPresentationControllerDelegate method
-prepareForPopoverPresentation.'
应用程序似乎在 AppDelegate 中崩溃。我不知道如何去做他们的建议。我也不知道这是否是更深层次问题的一部分,或者我是否遗漏了一些非常简单的东西。
我与 UIAlerts 相关的代码
以下是我与 UIAlertController 相关的 3 个函数
func webView(_ webView: WKWebView, runJavaScriptAlertPanelWithMessage message: String, initiatedByFrame frame: WKFrameInfo, completionHandler: @escaping () -> Void) {
let alertController = UIAlertController(title: nil, message: message, preferredStyle: .actionSheet)
alertController.addAction(UIAlertAction(title: "Ok", style: .default, handler: { (action) in
completionHandler()
}))
self.popoverPresentationController?.sourceView = self.view
self.popoverPresentationController?.sourceRect = self.view.bounds
self.present(alertController, animated: true, completion: nil)
}
func webView(_ webView: WKWebView, runJavaScriptConfirmPanelWithMessage message: String, initiatedByFrame frame: WKFrameInfo, completionHandler: @escaping (Bool) -> Void) {
let alertController = UIAlertController(title: nil, message: message, preferredStyle: .actionSheet)
alertController.addAction(UIAlertAction(title: "Yes", style: .default, handler: { (action) in
completionHandler(true)
}))
alertController.addAction(UIAlertAction(title: "No", style: .default, handler: { (action) in
completionHandler(false)
}))
self.popoverPresentationController?.sourceView = self.view
self.popoverPresentationController?.sourceRect = self.view.bounds
self.present(alertController, animated: true, completion: nil)
}
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: "Yes", style: .default, handler: { (action) in
if let text = alertController.textFields?.first?.text {
completionHandler(text)
} else {
completionHandler(defaultText)
}
}))
alertController.addAction(UIAlertAction(title: "No", style: .default, handler: { (action) in
completionHandler(nil)
}))
self.popoverPresentationController?.sourceView = self.view
self.popoverPresentationController?.sourceRect = self.view.bounds
self.present(alertController, animated: true, completion: nil)
}
如何处理此异常并解决此问题,以使我的应用不会在我身上崩溃?如果需要,我可以提供更多详细信息和代码。提前感谢您的帮助。
【问题讨论】:
标签: ios swift ipad ios-simulator swift3