ios8.4.1 webview黑屏
ios 8.4.1 webview black screen
我需要在 ios 中在一个简单的 webview 中创建一个应用程序。
我使用 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)
}
}
}
有没有示例代码?
谢谢。
我在我们的应用程序中遇到了类似的问题。这就是我在 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 中,但希望解决方案逻辑可以轻松转换为您的代码。
运行 当 Google Translate 触发我的 WKWebView
在执行回调后呈现空白页面时。这是与@dredful 相同的 iOS 10,swift 版本 - 这似乎掩盖了我看到的问题:
func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
if "about" == navigationAction.request.url?.scheme {
decisionHandler(.cancel);
webView.reload()
}
}
我需要在 ios 中在一个简单的 webview 中创建一个应用程序。 我使用 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)
}
}
}
有没有示例代码?
谢谢。
我在我们的应用程序中遇到了类似的问题。这就是我在 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 中,但希望解决方案逻辑可以轻松转换为您的代码。
运行 当 Google Translate 触发我的 WKWebView
在执行回调后呈现空白页面时。这是与@dredful 相同的 iOS 10,swift 版本 - 这似乎掩盖了我看到的问题:
func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
if "about" == navigationAction.request.url?.scheme {
decisionHandler(.cancel);
webView.reload()
}
}