Как начать WKWebViewConfiguration - PullRequest
0 голосов
/ 10 июня 2019

Как запустить WKWebViewConfiguration?

Я разрабатываю гибридное приложение с Cordova Wkwebview и пишу два метода init и WebView

но мне нужно

configuration.preferences.javaScriptCanOpenWindowsAutomatically = YES; 

значение до вызова webView, поэтому я пишу метод init (https://developer.apple.com/documentation/webkit/wkwebview/1414998-init)

но метод init не вызывается при запуске

как инициализировать значение configuration.preferences

- init:(CGRect *)frame :(WKWebViewConfiguration *)configuration {

    NSLog(@"init!!!!");

    configuration.preferences.javaScriptEnabled = YES;
    configuration.preferences.javaScriptCanOpenWindowsAutomatically = YES;


    return nil;
}


- (WKWebView *)webView:(WKWebView *)webView createWebViewWithConfiguration:(WKWebViewConfiguration *)configuration forNavigationAction:(WKNavigationAction *)navigationAction windowFeatures:(WKWindowFeatures *)windowFeatures
{

    webView.navigationDelegate = self;
    webView.UIDelegate = self;

    webView.configuration.preferences.javaScriptEnabled = YES;

webView.configuration.preferences.javaScriptCanOpenWindowsAutomatics = YES;

    if (navigationAction.request.URL) {

        NSURL *url = navigationAction.request.URL;
        NSString *urlPath = url.absoluteString;
        if ([urlPath rangeOfString:@"https://"].location != NSNotFound || [urlPath rangeOfString:@"http://"].location != NSNotFound) {
            [[UIApplication sharedApplication] openURL:url];
        }
    }

    return nil;
}
...