gpt4 book ai didi

ios 8.4.1 webview黑屏

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:39:51 25 4
gpt4 key购买 nike

我需要在一个简单的 webview 中制作一个 ios 应用程序。我用 example最近升级了 ios 8.4.1。升级后,应用程序停止工作,显示黑屏。

    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)

}

}

}

有没有示例代码?

谢谢。

screenshot

最佳答案

我在我们的应用程序中遇到了类似的问题。这就是我在 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 仅在第一次重新加载。

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

关于ios 8.4.1 webview黑屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32408352/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com