2017-02-09 3 views
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]; 
} 

答えて

0

申し訳ありませんが、私の悪いです。

あなただけのデリゲート本体に入れていない、すべてのアクション・コールバックでcompletionHandlerを使用する必要がありますので、このことができます

- (void)webView:(WKWebView *)webView runJavaScriptConfirmPanelWithMessage:(NSString *)message initiatedByFrame:(WKFrameInfo *)frame completionHandler:(void (^)(BOOL result))completionHandler{ 
    NSLog(@"runJavaScriptAlertPanelWithMessage:%@", message); 
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:message preferredStyle:UIAlertControllerStyleAlert]; 
    UIAlertAction *action = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { 
     NSLog(@"runJavaScriptConfirmPanelWithMessage:%@, did clicked", message); 
     completionHandler(YES); 
    }]; 
    UIAlertAction *actionCancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) { 
     NSLog(@"runJavaScriptConfirmPanelWithMessage:%@, did click cancel", message); 
     completionHandler(NO); 
    }]; 
    [alert addAction:action]; 
    [alert addAction:actionCancel]; 
    [self presentViewController:alert animated:YES completion:nil]; 
} 
関連する問題