我已将wkwebview集成到我的应用程序中 wkwebview需要很长时间才能加载。 第一次显示白屏,并在10-15秒后加载。 我怀疑这与加载有关吗?我只是不确定如何准确地确定我在做什么错。
WKPreferences * preferences = [[WKPreferences alloc] init]; preferences.javaScriptEnabled = YES;
// Disable zoom in/out in WKWebView
NSString *source = @"var meta = document.createElement('meta'); meta.name = 'viewport'; meta.content = 'width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no'; var head = document.getElementsByTagName('head')[0]; head.appendChild(meta);";
WKUserScript *script = [[WKUserScript alloc] initWithSource:source injectionTime:WKUserScriptInjectionTimeAtDocumentEnd forMainFrameOnly:YES];
WKUserContentController *userContentController = [[WKUserContentController alloc] init];
WKWebViewConfiguration *theConfiguration = [[WKWebViewConfiguration alloc] init];
theConfiguration.userContentController = userContentController;
[userContentController addUserScript:script];
WKWebView *webView = [[WKWebView alloc] initWithFrame:CGRectZero configuration:theConfiguration];
theConfiguration.preferences = preferences;
webView.scrollView.alwaysBounceHorizontal = NO;
webView.scrollView.showsVerticalScrollIndicator = NO;
webView.scrollView.showsHorizontalScrollIndicator = NO;
webView.scrollView.bounces = NO;
webView.scrollView.delegate = self;
webView.navigationDelegate = self;
webView.UIDelegate = self;
webView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth ;
[webView loadRequest:request];