Reputation: 148
I encountered a problem where my app, which worked perfectly in July, no longer works when I try to build it now.
Certain methods, such as the one below, are no longer being called in Xcode 16.1.
func webView(_ webView: WKWebView, runJavaScriptAlertPanelWithMessage message: String, initiatedByFrame frame: WKFrameInfo, completionHandler: @escaping () -> Void) {
let alertController = UIAlertController(title: nil, message: message, preferredStyle: UIDevice.current.userInterfaceIdiom == .pad ? .alert : .actionSheet)
alertController.addAction(
UIAlertAction(title: "Ok".localized, style: .default, handler: { (action) in completionHandler() })
)
if let controller = topMostViewController() {
controller.present(alertController, animated: true, completion: nil)
}
}
Upvotes: 0
Views: 64
Reputation: 148
I couldn’t find any information about this from Apple, but I tried using the async version of these methods, and it worked.
So, it seems you must use the async versions of these types of methods:
func webView(
_ webView: WKWebView,
runJavaScriptAlertPanelWithMessage message: String,
initiatedByFrame frame: WKFrameInfo
) async {
let alertController = UIAlertController(
title: nil,
message: message,
preferredStyle: UIDevice.current.userInterfaceIdiom == .pad ? .alert : .actionSheet
)
alertController.addAction(UIAlertAction(title: "Ok".localized, style: .default, handler: nil))
if let controller = topMostViewController() {
await MainActor.run {
controller.present(alertController, animated: true, completion: nil)
}
}
}
Upvotes: 0