Cordova UIWebView 在 iOS 上弃用

Cordova UIWebView deprecation on iOS

我正在使用 Ionic/Cordova 开发应用程序。 我在 2020 年 4 月 iOS 听到一些关于 Cordova UIWebView 弃用的谣言(所以它应该已经被弃用了)。

我想知道 Cordova 是否已经解决了这个问题,或者 Cordova 是否在 iOS 上完全被弃用,所以我应该切换到 Capacitor 或直接切换到 React-Native。

我选择 Ionic/Cordova 和 Angular 的原因是因为我需要用相同的代码构建一个移动应用程序和一个渐进式网络应用程序,并且看起来速度更快。

我还读到有一种方法可以切换到 WKWebView,但它仍然不稳定(不支持 cookie 持久性、XHR 请求和 iframe)。不管怎样,即使使用WKWebView,Cordova平台上仍然有UIWebView代码,所以它仍然会被Apple拒绝。

我希望 Cordova 的最新版本已经解决了这个问题,但我找不到任何东西。我还没有购买 Mac 来构建我的 iOS 平台,所以我无法检查自己。

有人有更新吗?

Cordova 团队已在 cordova-ios 版本 5.1.0 中修复此问题。如果你安装了最新版本,你就很好。

The Cordova team has released Cordova iOS 5.1.0, which disables UIWebview at compile time. To use it, ensure you have a WKWebView plugin installed, then add <preference name="WKWebViewOnly" value="true" /> to your config.xml file.

Ionic 的博客中有一篇关于此的文章:https://ionicframework.com/blog/understanding-itms-90809-uiwebview-api-deprecation/

Using Cordova?

On November 25th, 2019, the Cordova team released Cordova iOS 5.1.0, which disables UIWebview at compile time. They were previously discussing a plan to move forward.

To update:

  • Ensure you have a WKWebView plugin installed: either the official Apache one or Ionic’s. All Ionic starter apps automatically include cordova-plugin-ionic-webview.
  • Add <preference name="WKWebViewOnly" value="true" /> to your config.xml file.
  • Update each Cordova plugin to the latest version (these can trigger the warning too). Better yet – remove them if they are no longer needed!
  • Run cordova prepare ios to apply the changes.

To recap:

  • 5.1.0 has a conditional compile-time flag that disables UIWebView. This is an initial fix to prevent the Apple warning from being triggered.
  • 6.0.0 will remove the entirety of UIWebView. This is a breaking change with more changes needed, so it’ll be released sometime in the coming months. As of January 2020, no ETA for release is known but version 5.1.0 will work just fine.

Using the popular InAppBrowser plugin? The Cordova team released an update in January 2020. Be sure to update this plugin to version 3.2.0 and above.

Using Capacitor?

With this deprecation notice, now is the perfect time to consider migrating to Capacitor, Ionic’s spiritual successor to Cordova that enables modern web apps to run on all major platforms with ease.

On September 4th, 2019, the Ionic team shipped a new Capacitor release (here’s the v1.2.0 changelog) that removed references to UIWebView. To update your app, simply run the following commands to update the Capacitor iOS library:

npm update @capacitor/cli 
npm update @capacitor/core 
npm update @capacitor/ios 
npx cap sync

You may notice “UIWebView” references within your Capacitor-based iOS project. Files within the “CapacitorCordova” pod, for example, relate to Cordova compatibility. These will not trigger the warning.

Please note that if you’re using Cordova plugins in your Capacitor project, you’ll need to ensure those are updated before Apple’s deadline. If they can’t be updated, they’ll have to be removed from your project.

如果您想创建新项目,我鼓励您使用 Capacitor 而不是 Cordova,以使用最新技术并更好地控制本机项目。