0
我使用this project讓我開始使用OSX下的WebKit框架。爲什麼WebView無法使用字符串加載外部URL?
它在本地加載資源,我已經能夠得到它的工作。然而,當我改變awakeFromNib加載像一個URL字符串像http://www.example.com/index.html
它不起作用,視圖是空白的,即使這是一個有效的URL。
原文:
- (void)awakeFromNib {
WebPreferences *prefs = [webView preferences];
[prefs _setLocalStorageDatabasePath:@"~/Library/WebViewExample/LocalStorage"];
NSString *resourcesPath = [[NSBundle mainBundle] resourcePath];
NSString *htmlPath = [resourcesPath stringByAppendingString:@"/htdocs/640x480_naked.html"];
[[webView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:htmlPath]]];
}
修改爲外部URL:
- (void)awakeFromNib {
WebPreferences *prefs = [webView preferences];
[prefs _setLocalStorageDatabasePath:@"/tmp"];
NSString *urlText = @"http://www.example.com/index.html";
[[webView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlText]]];
}
出了什麼問題?
可能與運輸安全有關? http://stackoverflow.com/questions/30731785/how-do-i-load-an-http-url-with-app-transport-security-enabled-in-ios-9 – danh
@danh - 謝謝!事實證明是這樣。 – Matt