Hello, I have an 'NSInternalInconsistencyException': 'Completion handler passed to -[ViewController webView:runJavaScriptAlertPanelWithMessage:initiatedByFrame:completionHandler:] was not called'
JavaScript sends message to wkwebkit, and imediatelly after runs alert('test') (from same jscript function) The message sent to webkit will trigger some UI to come up from 3rd party pod (via presentViewController), and the return, and alert will get fired from script. The alert is NOT visible now (because the UI from pod came up), But now when I dismiss the ui, the app trhows exception above. What dismisses the alert (or why does alert's completion routine is not called if it wasn't dismissed with button)? Script part: <script ...> window.webkit.messageHandlers.external.postMessage({some json data} ); alert('test'); </script> cocoa in webkit to receive messages: - (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message { //... AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication] delegate]; [app someDelegateMethod]; //... } // now in app delegate: - (void) someDelegateMethod { //... UIViewController *uiView = [[... //this returned from a 3rd party cocoa pod) [[self topViewController] presentViewController:uiView animated:YES completion:nil]; //... } // wk alert message - (void)webView:(WKWebView *)webView runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(void))completionHandler { UIAlertController *alertController = [UIAlertController alertControllerWithTitle:webView.URL.host message:message preferredStyle:UIAlertControllerStyleAlert]; [alertController addAction:[UIAlertAction actionWithTitle:NSLocalizedString(@"Close", "Close (panel/dialog/alert)") style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) { completionHandler(); }]]; [self presentViewController:alertController animated:YES completion:nil]; } // utils, for getting topViewController - (UIViewController*)topViewController { return [self topViewControllerWithRootViewController:[UIApplication sharedApplication].keyWindow.rootViewController]; } - (UIViewController*)topViewControllerWithRootViewController:(UIViewController*)rootViewController { if ([rootViewController isKindOfClass:[UITabBarController class]]) { UITabBarController* tabBarController = (UITabBarController*)rootViewController; return [self topViewControllerWithRootViewController:tabBarController.selectedViewController]; } else if ([rootViewController isKindOfClass:[UINavigationController class]]) { UINavigationController* navigationController = (UINavigationController*)rootViewController; return [self topViewControllerWithRootViewController:navigationController.visibleViewController]; } else if (rootViewController.presentedViewController) { UIViewController* presentedViewController = rootViewController.presentedViewController; return [self topViewControllerWithRootViewController:presentedViewController]; } else { return rootViewController; } } Thank you _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com