我正在对 WKWebView 进行快速测试以评估其优缺点。但我发现我能够使用 Xcode 6.4 和 iOS 8 加载 url,但在 Xcode 7 beta 3 中加载相同的 URL 时遇到问题。
这就是我正在做的事情:
- (void)viewDidLoad {
[super viewDidLoad];
// First create a WKWebViewConfiguration object so we can add a controller
// pointing back to this ViewController.
WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc]
init];
WKUserContentController *controller = [[WKUserContentController alloc]
init];
// Add a script handler for the "observe" call. This is added to every frame
// in the document (window.webkit.messageHandlers.NAME).
[controller addScriptMessageHandler:self name:@"observe"];
configuration.userContentController = controller;
// This is the URL to be loaded into the WKWebView.
NSURL *jsbin = [NSURL URLWithString:k_JSBIN_URL3];
// Initialize the WKWebView with the current frame and the configuration
// setup above
_webView = [[WKWebView alloc] initWithFrame:self.view.frame
configuration:configuration];
// Load the jsbin URL into the WKWebView and then add it as a sub-view.
[_webView loadRequest:[NSURLRequest requestWithURL:jsbin]];
[self.view addSubview:_webView];
}
我做错了什么还是只是 Xcode 和 iOS 9 的测试版?谢谢,