迁移到WKWebView [英] Migrate to WKWebView
问题描述
我试图了解如何在iOS8中使用新的WKWebView,找不到太多信息。我读过:
I'm trying to understand how to make use of the new WKWebView in iOS8, can't find much information. I've read:
http://developer.telerik.com/featured/why-ios-8s-wkwebview-is-a-big-deal-for-hybrid-development/
http://nshipster.com/wkwebkit/
但是这对现有应用有何影响?普通的UiWebView会从nitro java脚本引擎获得加速,还是我们需要进行更改?我们如何处理向后兼容性?
But how does this affect existing apps? Will an ordinary UiWebView get the speedup from the nitro java script engine or do we need to make changes? How do we deal with backwards compatibility?
我能找到的所有代码和示例都使用swift,这是强制性的吗?
All the code and examples I can find are using swift, will this be mandatory?
感谢您对此事的任何帮助!
Thankful for any help on this matter!
推荐答案
UIWebView
仍将继续使用现有应用。 WKWebView
从 iOS8
开始,只有 WKWebView
有一个Nitro JavaScript引擎。
UIWebView
will still continue to work with existing apps. WKWebView
is available starting from iOS8
, only WKWebView
has a Nitro JavaScript engine.
要在较旧的应用程序中利用这个更快的JavaScript引擎,您必须更改代码以使用 WKWebView
而不是的UIWebView
。对于 iOS7
及更早版本,您必须继续使用 UIWebView
,因此您可能需要检查 iOS8
然后应用 WKWebView
方法/委托方法并回退到 UIWebView
方法 iOS7
及更早版本。此外, WKWebView
(还)没有Interface Builder组件,因此您必须以编程方式实现 WKWebView
。
To take advantage of this faster JavaScript engine in older apps you have to make code changes to use WKWebView
instead of UIWebView
. For iOS7
and older, you have to continue to use UIWebView
, so you may have to check for iOS8
and then apply WKWebView
methods / delegate methods and fallback to UIWebView
methods for iOS7
and older. Also there is no Interface Builder component for WKWebView
(yet), so you have to programmatically implement WKWebView
.
您可以在Objective-C中实现 WKWebView
,这是启动 WKWebView的简单示例
:
You can implement WKWebView
in Objective-C, here is simple example to initiate a WKWebView
:
WKWebViewConfiguration *theConfiguration = [[WKWebViewConfiguration alloc] init];
WKWebView *webView = [[WKWebView alloc] initWithFrame:self.view.frame configuration:theConfiguration];
webView.navigationDelegate = self;
NSURL *nsurl=[NSURL URLWithString:@"http://www.apple.com"];
NSURLRequest *nsrequest=[NSURLRequest requestWithURL:nsurl];
[webView loadRequest:nsrequest];
[self.view addSubview:webView];
WKWebView
WebGL游戏中渲染性能显着以及运行复杂JavaScript算法的东西,如果你使用webview加载一个简单的html或网站,你可以继续使用 UIWebView
。
WKWebView
rendering performance is noticeable in WebGL games and something that runs complex JavaScript algorithms, if you are using webview to load a simple html or website, you can continue to use UIWebView
.
这是一个测试 app 可用于使用 UIWebView
或 WKWebView
打开任何网站,您可以比较性能,然后决定升级您的应用程序以使用 WKWebView
:
https://itunes.apple.com/app/id928647773?mt=8&at=10ltWQ
Here is a test app that can used to open any website using either UIWebView
or WKWebView
and you can compare performance, and then decide on upgrading your app to use WKWebView
:
https://itunes.apple.com/app/id928647773?mt=8&at=10ltWQ
这篇关于迁移到WKWebView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!