Choosing Your WebView in iOS
What's a WebView
A WebView is simply a UI component used to display web content within an app. You can think of mobile Safari as a collection of webviews. Astro is built on top of webviews, not only using them to display web content but also to perform messaging between web and native iOS components.
The Two Options in iOS
In iOS there are two different webview technologies available, each with it's own pros and cons. Historically only UIWebView was available in Astro, however, WKWebView was recently added on an opt-in basis to provide additional features, flexibility, and performance.
UIWebView is the original webview component introduced in iOS 2.0. This is what has been used since the early days of iOS to build hybrid applications or display any web content within a native app. This is the webview that Astro was originally built on and remains the default for iOS 8.
- UIWebView has been around for a while and therefore flaws, bugs, and workarounds are well documented.
Pitfalls & Problems
- Known to be prone to crashes when encountering rendering bugs triggered by the page
- Mobile Safari loads and renders pages 2-3x quicker than a UIWebView
- Changes made to mobile Safari often never make it to UIWebView (especially things like new web standards conformance such as HTML 5)
- Scrolling a page while it is loading blocks further loading (e.g. images that are loading will not display until the scroll event has ended). Animated images are blocked from animating during scrolling.
- Better HTML5 support
- Significant performance gains in WebGL applications
- More reliable with bad HTML/CSS/JS
- Animated images are never paused during scrolling
- 60fps scrolling
- Better maintenance and quicker access to patches as much of this technology is shared with mobile Safari
Pitfalls & Problems
- Cannot display the keyboard programmatically as called out here
- Stability has greatly improved as of iOS 9 but remains a bit of a problem in iOS 8 (multiple workarounds within Astro were required to get WKWebView working for iOS 8). As a result, WKWebView is not supported in iOS 8.
How To Enable WKWebView
Astro promotes using the best web view component for all situations. As a result
the default for iOS 9+ is WKWebView and UIWebView for iOS 8. The best web view
will be selected on startup based on the version of iOS your app is running on.
In rare cases you may need to use UIWebView for all platforms (for example, if
you run into a problem where WKWebView doesn't work properly with your website).
In this case you can force Astro to use UIWebView for all platforms by adding
the following line in your AppDelegate's
AstroConfig.useWKWebView = false