iOS 8.4.1 WebView黑屏 [英] ios 8.4.1 webview black screen

查看:91
本文介绍了iOS 8.4.1 WebView黑屏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在一个简单的Webview中的ios中创建一个应用程序. 我使用

I need to make an application in ios in a simple webview. I use example recently upgraded ios 8.4.1. After the upgrade, the application stops working, displays a black screen.

    import UIKit
import WebKit

class ViewController: UIViewController, WKNavigationDelegate {
  var webView: WKWebView?

  /* Start the network activity indicator when the web view is loading */
  func webView(webView: WKWebView,
    didStartProvisionalNavigation navigation: WKNavigation){
      UIApplication.sharedApplication().networkActivityIndicatorVisible = true
  }

  /* Stop the network activity indicator when the loading finishes */
  func webView(webView: WKWebView,
    didFinishNavigation navigation: WKNavigation){
      UIApplication.sharedApplication().networkActivityIndicatorVisible = false
  }

  func webView(webView: WKWebView,
    decidePolicyForNavigationResponse navigationResponse: WKNavigationResponse,
    decisionHandler: ((WKNavigationResponsePolicy) -> Void)){

      print(navigationResponse.response.MIMEType)

      decisionHandler(.Allow)

  }

  override func viewDidLoad() {
    super.viewDidLoad()

    /* Create our preferences on how the web page should be loaded */
    let preferences = WKPreferences()
    preferences.javaScriptEnabled = false

    /* Create a configuration for our preferences */
    let configuration = WKWebViewConfiguration()
    configuration.preferences = preferences

    /* Now instantiate the web view */
    webView = WKWebView(frame: view.bounds, configuration: configuration)

    if let theWebView = webView{
      /* Load a web page into our web view */
      let url = NSURL(string: "http://www.apple.com")
      let urlRequest = NSURLRequest(URL: url!)
      theWebView.loadRequest(urlRequest)
      theWebView.navigationDelegate = self
      view.addSubview(theWebView)

    }

  }

}

是否有示例代码?

谢谢.

推荐答案

我的应用中发生了类似的问题.这就是我在Objective-C中解决问题的方式:

I had a similar issue happen in our app. This is how I solved it in Objective-C:

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {

    NSLog(@"request.URL.scheme: %@", request.URL.scheme);

    BOOL calledForReload = NO;

    if ([[request.URL.scheme lowercaseString] isEqualToString:@"about"]) {
         //have we used reload yet?
        if (!calledForReload) {
            calledForReload = YES;
            [webView reload];
        } else {
            // other response
            // decide what you wish to do if you get another about:blank
        }
    }

return YES;
}

基本上,我看到iOS 8.4.1 UIWebView突然将about:blank作为第一个URL.我的解决方案是检查about:blank并要求UIWebView仅在第一次时重新加载.

Basically I saw iOS 8.4.1 UIWebView suddenly calls about:blank as the first URL. My solution was to check for about:blank and ask the UIWebView to reload only the first time.

答案不在SWIFT中,但是希望解决方案逻辑可以轻松地转换为您的代码.

The answer is not in SWIFT, but hopefully the solution logic is easily translated to your code.

这篇关于iOS 8.4.1 WebView黑屏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆