NSInternalInconsistencyException issue with WKUIDelegate's runJavaScriptAlertPanelWithMessage on iOS 16.4.1

Hello,

I'm developing an iOS application in Swift, where I use WKWebView to display web content.

Until iOS 16.1, there were no issues, but starting from iOS 16.4.1, I encounter an "NSInternalInconsistencyException - Completion handler was not call" exception when the app transitions to terminated while a UIAlertController is still open.

Here's a snippet of the relevant code:

func webView(_ webView: WKWebView, runJavaScriptAlertPanelWithMessage message: String, initiatedByFrame frame: WKFrameInfo, completionHandler: @escaping () -> Void) {
    let alertController = UIAlertController(title: "", message: message, preferredStyle: .alert)

    alertController.addAction(UIAlertAction(title: "OK", style: .default, handler: { (action) in completionHandler() }))

    self.present(alertController, animated: true, completion: nil)
}

If anyone is familiar with this issue or could suggest a way to resolve it, your assistance would be greatly appreciated.

Thank you.

NSInternalInconsistencyException issue with WKUIDelegate's runJavaScriptAlertPanelWithMessage on iOS 16.4.1
 
 
Q