Search code examples
iosangularcordovaionic-frameworkuiwebview

Cordova UIWebView deprecation on iOS


I'm developing an Application using Ionic/Cordova. I heard some rumors about Cordova UIWebView deprecation on iOS in April 2020 (so it should already be deprecated).

I would like to understand if Cordova has already fixed this issue or if Cordova has totally become deprecated on iOS so i should switch to Capacitor or directly to React-Native.

The reason why i've chosen Ionic/Cordova with Angular is because i need to build in the same code a mobile application and a progressive web app and looks the faster way.

I also read there is a way to switch to WKWebView, but it's still unstable (not supporting cookies persistance, XHR requests and iframes). Anyway, even using WKWebView, there would still be UIWebView code on Cordova platform so it would still be rejected from Apple.

I hope Cordova newest versions already fixed this problem, but i couldn't find anything. I still haven't bought a Mac to build my iOS platform so i can't check myself.

Anyone has any update?


Solution

  • Cordova team already fixed this in cordova-ios version 5.1.0. If you installed the latest version, you are good.

    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.

    There is an article for this in Ionic's blog: 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.

    If you want to create new project, I encourage you to use Capacitor over Cordova to work with latest technologies and have more control of the native project.