如何迁移到WKWebView? [英] How to 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是从硝基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?
感谢您对此事的帮助!
推荐答案
UIWebView
仍将继续与现有应用一起使用.从iOS8
开始可以使用WKWebView
,只有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
方法/委托方法,并回退到iOS7
和更早版本的UIWebView
方法.此外,还没有用于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
.
这是一个可以用来打开的测试应用任何使用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屋!