summaryrefslogtreecommitdiff
path: root/StoneIsland/plugins/cordova-plugin-wkwebview-engine/src/ios/CDVWKWebViewUIDelegate.m
diff options
context:
space:
mode:
authorJules Laplace <julescarbon@gmail.com>2017-10-25 18:19:08 +0200
committerJules Laplace <julescarbon@gmail.com>2017-10-25 18:19:08 +0200
commit531c60ee7ecbee516812d560b63a8317c3cf3590 (patch)
treef2d85569a113a6f9056de3fdd5d4272c0b3406a6 /StoneIsland/plugins/cordova-plugin-wkwebview-engine/src/ios/CDVWKWebViewUIDelegate.m
parent4da1d17b84d25fb4b34e583e4bf3b64f5ad2e147 (diff)
hide statusbar
Diffstat (limited to 'StoneIsland/plugins/cordova-plugin-wkwebview-engine/src/ios/CDVWKWebViewUIDelegate.m')
-rw-r--r--StoneIsland/plugins/cordova-plugin-wkwebview-engine/src/ios/CDVWKWebViewUIDelegate.m123
1 files changed, 123 insertions, 0 deletions
diff --git a/StoneIsland/plugins/cordova-plugin-wkwebview-engine/src/ios/CDVWKWebViewUIDelegate.m b/StoneIsland/plugins/cordova-plugin-wkwebview-engine/src/ios/CDVWKWebViewUIDelegate.m
new file mode 100644
index 00000000..a7a16f2c
--- /dev/null
+++ b/StoneIsland/plugins/cordova-plugin-wkwebview-engine/src/ios/CDVWKWebViewUIDelegate.m
@@ -0,0 +1,123 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+ */
+
+#import "CDVWKWebViewUIDelegate.h"
+
+@implementation CDVWKWebViewUIDelegate
+
+- (instancetype)initWithTitle:(NSString*)title
+{
+ self = [super init];
+ if (self) {
+ self.title = title;
+ }
+
+ return self;
+}
+
+- (void) webView:(WKWebView*)webView runJavaScriptAlertPanelWithMessage:(NSString*)message
+ initiatedByFrame:(WKFrameInfo*)frame completionHandler:(void (^)(void))completionHandler
+{
+ UIAlertController* alert = [UIAlertController alertControllerWithTitle:self.title
+ message:message
+ preferredStyle:UIAlertControllerStyleAlert];
+
+ UIAlertAction* ok = [UIAlertAction actionWithTitle:NSLocalizedString(@"OK", @"OK")
+ style:UIAlertActionStyleDefault
+ handler:^(UIAlertAction* action)
+ {
+ completionHandler();
+ [alert dismissViewControllerAnimated:YES completion:nil];
+ }];
+
+ [alert addAction:ok];
+
+ UIViewController* rootController = [UIApplication sharedApplication].delegate.window.rootViewController;
+
+ [rootController presentViewController:alert animated:YES completion:nil];
+}
+
+- (void) webView:(WKWebView*)webView runJavaScriptConfirmPanelWithMessage:(NSString*)message
+ initiatedByFrame:(WKFrameInfo*)frame completionHandler:(void (^)(BOOL result))completionHandler
+{
+ UIAlertController* alert = [UIAlertController alertControllerWithTitle:self.title
+ message:message
+ preferredStyle:UIAlertControllerStyleAlert];
+
+ UIAlertAction* ok = [UIAlertAction actionWithTitle:NSLocalizedString(@"OK", @"OK")
+ style:UIAlertActionStyleDefault
+ handler:^(UIAlertAction* action)
+ {
+ completionHandler(YES);
+ [alert dismissViewControllerAnimated:YES completion:nil];
+ }];
+
+ [alert addAction:ok];
+
+ UIAlertAction* cancel = [UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", @"Cancel")
+ style:UIAlertActionStyleDefault
+ handler:^(UIAlertAction* action)
+ {
+ completionHandler(NO);
+ [alert dismissViewControllerAnimated:YES completion:nil];
+ }];
+ [alert addAction:cancel];
+
+ UIViewController* rootController = [UIApplication sharedApplication].delegate.window.rootViewController;
+
+ [rootController presentViewController:alert animated:YES completion:nil];
+}
+
+- (void) webView:(WKWebView*)webView runJavaScriptTextInputPanelWithPrompt:(NSString*)prompt
+ defaultText:(NSString*)defaultText initiatedByFrame:(WKFrameInfo*)frame
+ completionHandler:(void (^)(NSString* result))completionHandler
+{
+ UIAlertController* alert = [UIAlertController alertControllerWithTitle:self.title
+ message:prompt
+ preferredStyle:UIAlertControllerStyleAlert];
+
+ UIAlertAction* ok = [UIAlertAction actionWithTitle:NSLocalizedString(@"OK", @"OK")
+ style:UIAlertActionStyleDefault
+ handler:^(UIAlertAction* action)
+ {
+ completionHandler(((UITextField*)alert.textFields[0]).text);
+ [alert dismissViewControllerAnimated:YES completion:nil];
+ }];
+
+ [alert addAction:ok];
+
+ UIAlertAction* cancel = [UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", @"Cancel")
+ style:UIAlertActionStyleDefault
+ handler:^(UIAlertAction* action)
+ {
+ completionHandler(nil);
+ [alert dismissViewControllerAnimated:YES completion:nil];
+ }];
+ [alert addAction:cancel];
+
+ [alert addTextFieldWithConfigurationHandler:^(UITextField* textField) {
+ textField.text = defaultText;
+ }];
+
+ UIViewController* rootController = [UIApplication sharedApplication].delegate.window.rootViewController;
+
+ [rootController presentViewController:alert animated:YES completion:nil];
+}
+
+@end