WKWebView is a browser component that Apple introduced in iOS 8 to replace the outdated UIWebView component. It features multi-process rendering, which means that page scrolling does not affect image resource loading, crashes do not affect the main process, and memory usage is lower. Compared to UIWebView, WKWebView offers significant improvements in performance, stability, and user experience. After several years of development and refinement across multiple iOS versions, WKWebView has resolved its initial issues and is now stable.
After the release of iOS 12, Apple's APIs began to show deprecation warnings for UIWebView. By August 2019, any app that used the UIWebView component received a warning when submitted to the App Store for review. The warning advised developers to switch to WKWebView as soon as possible.
On December 23, 2019, Apple announced that the App Store would no longer accept new apps developed with UIWebView starting in April 2020. The company also announced that updates for existing apps using UIWebView would no longer be accepted starting in December 2020.
In response, mPaaS was adapted for WKWebView to support the switch from UIWebView. To ensure the stability of HTML5 pages after the switch, the adaptation occurs in two phases:
Phase 1: Starting in November 2019, the mPaaS baseline supports both UIWebView and WKWebView. It uses a grayscale release to gradually switch to WKWebView.
Phase 2: Starting in March 2020, the mPaaS baseline completely removes UIWebView-related code. All H5 services are switched to WKWebView.
The mPaaS 10.1.60 baseline has completed the first phase of adaptation. If you have integrated the mPaaS H5 Container and miniapp components, you should upgrade to the 10.1.60 baseline (Upgrade the baseline) and switch to WKWebView (Use WKWebView) as soon as possible.
Upgrade the baseline
If you have integrated the mPaaS H5 Container and miniapp components, select the appropriate baseline for your upgrade to WKWebView based on your application's release status.
For legacy applications listed on the App Store before April 2020: To ensure the stability of your existing services when switching to WKWebView, upgrade to the 10.1.60 baseline. This version supports online grayscale release and rollback capabilities. For more information about the upgrade, see 10.1.60 Official Release Upgrade Guide.
For new applications not yet listed on the App Store before April 2020: The App Store will not accept new apps that use UIWebView after April. Therefore, use version 10.1.68, which completely removes UIWebView-related code. Also, perform thorough regression testing for your services. For more information about the upgrade, see mPaaS 10.1.68-beta Upgrade Guide.
Use WKWebView
By default, the mPaaS container uses UIWebView to load HTML5 pages. The framework lets you enable WKWebView in two ways: globally or through a grayscale release.
10.1.60 baseline
In the 10.1.60 baseline, the mPaaS container includes both UIWebView and WKWebView. By default, it uses UIWebView to load HTML5 pages. You can enable the global WKWebView switch to make all pages loaded by the mPaaS container use WKWebView.
- (void)application:(UIApplication *)application afterDidFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
//...
// Enable the global WKWebView switch
[MPNebulaAdapterInterface shareInstance].nebulaUseWKArbitrary = YES;
//...
}After you enable WKWebView, check the User Agent (UA) of the current HTML5 page. If the UA contains the string WK, as shown in the following figure, the page has successfully switched to WKWebView.
Other information
After you enable WKWebView globally, the mPaaS framework provides an immediate remediation capability to ensure the stability of online HTML5 page features. This capability lets you quickly switch from WKWebView back to UIWebView. To do this, you can add a configuration switch in the real-time release component to restrict usage to UIWebView at the offline package or URL dimension.
The Configuration key (key) for this switch is h5_wkArbitrary, and the Resource value (value) is as follows:
{
"enable": true,
"enableSubView": false,
"exception": [
{
"appId": "^(70000000|20000193)$"
},
{
"url": "https://invoice[.]starbucks[.]com[.]cn/"
},
{
"url":"https://front[.]verystar[.]cn/starbucks/alipay-invoice"
}]
}The following table describes the configuration items for the value.
Configuration item | Description | Notes | |
enable | Specifies whether to enable WKWebView. | The default value is | |
enableSubView | Specifies whether to enable WKWebView for webViews embedded in miniapps. | The default value is | |
exception | appId | All HTML5 pages in offline packages whose appIDs match the regular expression will not use WKWebView. | The default value is |
url | All HTML5 pages whose URLs match the regular expression will not use WKWebView. | ||
10.1.68-beta baseline
In version 10.1.68-beta, the container uses WKWebView by default to load offline packages and miniapps. Check the UA of the current HTML5 page. If the UA contains the string WK, as shown in the following figure, the page is successfully using WKWebView.