0
に
エラー正常に動作することはできません。アラートが(「?OK」(確認))WKWebview
Warning: Attempt to present on which is already presenting
をそれがにどのような方法があり、WKWebviewのデリゲートで同時にビューコントローラを提示alert(confirm('ok?'));
スタイルのコードのトリガーと思われますこれをサポートしていますか?
私のhtml:
<button onclick="alert(1);">alert</button><br>
<button onclick="alert(confirm('ok?'));">confirm</button><br>
<button onclick="alert(prompt('please input'));">text</button><br>
私のコード:
- (void)webView:(WKWebView *)webView runJavaScriptAlertPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(void))completionHandler{
NSLog(@"runJavaScriptAlertPanelWithMessage:%@", message);
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"TITLE" message:message preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *action = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"runJavaScriptAlertPanelWithMessage:%@, did clicked", message);
}];
[alert addAction:action];
completionHandler();
[self presentViewController:alert animated:YES completion:nil];
}
- (void)webView:(WKWebView *)webView runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(BOOL result))completionHandler{
NSLog(@"runJavaScriptAlertPanelWithMessage:%@", message);
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"TITLE" message:message preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *action = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"runJavaScriptConfirmPanelWithMessage:%@, did clicked yes", message);
}];
UIAlertAction *actionCancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
NSLog(@"runJavaScriptConfirmPanelWithMessage:%@, did click cancel", message);
}];
[alert addAction:action];
[alert addAction:actionCancel];
completionHandler(YES);
[self presentViewController:alert animated:YES completion:nil];
}