1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 | #import "CDVWKInAppBrowserUIDelegate.h"
|
21 |
|
22 | @implementation CDVWKInAppBrowserUIDelegate
|
23 |
|
24 | - (instancetype)initWithTitle:(NSString*)title
|
25 | {
|
26 | self = [super init];
|
27 | if (self) {
|
28 | self.title = title;
|
29 | }
|
30 |
|
31 | return self;
|
32 | }
|
33 |
|
34 | - (void) webView:(WKWebView*)webView runJavaScriptAlertPanelWithMessage:(NSString*)message
|
35 | initiatedByFrame:(WKFrameInfo*)frame completionHandler:(void (^)(void))completionHandler
|
36 | {
|
37 | UIAlertController* alert = [UIAlertController alertControllerWithTitle:self.title
|
38 | message:message
|
39 | preferredStyle:UIAlertControllerStyleAlert];
|
40 |
|
41 | UIAlertAction* ok = [UIAlertAction actionWithTitle:NSLocalizedString(@"OK", @"OK")
|
42 | style:UIAlertActionStyleDefault
|
43 | handler:^(UIAlertAction* action)
|
44 | {
|
45 | completionHandler();
|
46 | [alert dismissViewControllerAnimated:YES completion:nil];
|
47 | }];
|
48 |
|
49 | [alert addAction:ok];
|
50 |
|
51 | [[self getViewController] presentViewController:alert animated:YES completion:nil];
|
52 | }
|
53 |
|
54 | - (void) webView:(WKWebView*)webView runJavaScriptConfirmPanelWithMessage:(NSString*)message
|
55 | initiatedByFrame:(WKFrameInfo*)frame completionHandler:(void (^)(BOOL result))completionHandler
|
56 | {
|
57 | UIAlertController* alert = [UIAlertController alertControllerWithTitle:self.title
|
58 | message:message
|
59 | preferredStyle:UIAlertControllerStyleAlert];
|
60 |
|
61 | UIAlertAction* ok = [UIAlertAction actionWithTitle:NSLocalizedString(@"OK", @"OK")
|
62 | style:UIAlertActionStyleDefault
|
63 | handler:^(UIAlertAction* action)
|
64 | {
|
65 | completionHandler(YES);
|
66 | [alert dismissViewControllerAnimated:YES completion:nil];
|
67 | }];
|
68 |
|
69 | [alert addAction:ok];
|
70 |
|
71 | UIAlertAction* cancel = [UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", @"Cancel")
|
72 | style:UIAlertActionStyleDefault
|
73 | handler:^(UIAlertAction* action)
|
74 | {
|
75 | completionHandler(NO);
|
76 | [alert dismissViewControllerAnimated:YES completion:nil];
|
77 | }];
|
78 | [alert addAction:cancel];
|
79 |
|
80 | [[self getViewController] presentViewController:alert animated:YES completion:nil];
|
81 | }
|
82 |
|
83 | - (void) webView:(WKWebView*)webView runJavaScriptTextInputPanelWithPrompt:(NSString*)prompt
|
84 | defaultText:(NSString*)defaultText initiatedByFrame:(WKFrameInfo*)frame
|
85 | completionHandler:(void (^)(NSString* result))completionHandler
|
86 | {
|
87 | UIAlertController* alert = [UIAlertController alertControllerWithTitle:self.title
|
88 | message:prompt
|
89 | preferredStyle:UIAlertControllerStyleAlert];
|
90 |
|
91 | UIAlertAction* ok = [UIAlertAction actionWithTitle:NSLocalizedString(@"OK", @"OK")
|
92 | style:UIAlertActionStyleDefault
|
93 | handler:^(UIAlertAction* action)
|
94 | {
|
95 | completionHandler(((UITextField*)alert.textFields[0]).text);
|
96 | [alert dismissViewControllerAnimated:YES completion:nil];
|
97 | }];
|
98 |
|
99 | [alert addAction:ok];
|
100 |
|
101 | UIAlertAction* cancel = [UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", @"Cancel")
|
102 | style:UIAlertActionStyleDefault
|
103 | handler:^(UIAlertAction* action)
|
104 | {
|
105 | completionHandler(nil);
|
106 | [alert dismissViewControllerAnimated:YES completion:nil];
|
107 | }];
|
108 | [alert addAction:cancel];
|
109 |
|
110 | [alert addTextFieldWithConfigurationHandler:^(UITextField* textField) {
|
111 | textField.text = defaultText;
|
112 | }];
|
113 |
|
114 | [[self getViewController] presentViewController:alert animated:YES completion:nil];
|
115 | }
|
116 |
|
117 | -(UIViewController*) getViewController
|
118 | {
|
119 | return _viewController;
|
120 | }
|
121 |
|
122 | -(void) setViewController:(UIViewController*) viewController
|
123 | {
|
124 | _viewController = viewController;
|
125 | }
|
126 |
|
127 | @end
|