@@ -477,4 +477,58 @@ - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
477477 }
478478}
479479
480+ #pragma mark -- WKUIDelegate
481+ - (void )webView : (WKWebView *)webView runJavaScriptAlertPanelWithMessage : (NSString *)message initiatedByFrame : (WKFrameInfo *)frame completionHandler : (void (^)(void ))completionHandler
482+ {
483+ UIAlertController *alert = [UIAlertController alertControllerWithTitle: nil
484+ message: message
485+ preferredStyle: UIAlertControllerStyleAlert];
486+
487+ [alert addAction: [UIAlertAction actionWithTitle: NSLocalizedString(@" OK" , nil ) style: UIAlertActionStyleCancel handler: ^(UIAlertAction *action) {
488+ completionHandler ();
489+ }]];
490+
491+ [self .viewController presentViewController: alert animated: YES completion: nil ];
492+ }
493+
494+ - (void )webView : (WKWebView *)webView runJavaScriptConfirmPanelWithMessage : (NSString *)message initiatedByFrame : (WKFrameInfo *)frame completionHandler : (void (^)(BOOL result))completionHandler
495+ {
496+ UIAlertController *alert = [UIAlertController alertControllerWithTitle: nil
497+ message: message
498+ preferredStyle: UIAlertControllerStyleAlert];
499+
500+ [alert addAction: [UIAlertAction actionWithTitle: NSLocalizedString(@" Cancel" , nil ) style: UIAlertActionStyleCancel handler: ^(UIAlertAction *action) {
501+ completionHandler (NO );
502+ }]];
503+
504+ [alert addAction: [UIAlertAction actionWithTitle: NSLocalizedString(@" OK" , nil ) style: UIAlertActionStyleDefault handler: ^(UIAlertAction *action) {
505+ completionHandler (YES );
506+ }]];
507+
508+ [self .viewController presentViewController: alert animated: YES completion: nil ];
509+ }
510+
511+ - (void )webView : (WKWebView *)webView runJavaScriptTextInputPanelWithPrompt : (NSString *)prompt defaultText : (NSString *)defaultText initiatedByFrame : (WKFrameInfo *)frame completionHandler : (void (^)(NSString *result))completionHandler
512+ {
513+ UIAlertController *alert = [UIAlertController alertControllerWithTitle: nil
514+ message: prompt
515+ preferredStyle: UIAlertControllerStyleAlert];
516+
517+ [alert addTextFieldWithConfigurationHandler: ^(UITextField *textField) {
518+ textField.placeholder = prompt;
519+ textField.secureTextEntry = NO ;
520+ textField.text = defaultText;
521+ }];
522+
523+ [alert addAction: [UIAlertAction actionWithTitle: NSLocalizedString(@" Cancel" , nil ) style: UIAlertActionStyleCancel handler: ^(UIAlertAction *action) {
524+ completionHandler (nil );
525+ }]];
526+
527+ [alert addAction: [UIAlertAction actionWithTitle: NSLocalizedString(@" OK" , nil ) style: UIAlertActionStyleDefault handler: ^(UIAlertAction *action) {
528+ completionHandler ([alert.textFields.firstObject text ]);
529+ }]];
530+
531+ [self .viewController presentViewController: alert animated: YES completion: nil ];
532+ }
533+
480534@end
0 commit comments