Recently I had to generate new iOS and Android versions of an app that had been created in Visual Studio 2015 using the Visual Studio Tools for Apache Cordova. This wasn't... easy. In this post, I will summarize some of the challenges I encountered and the solutions I found.

The first problem I found was that newer versions of Visual Studio no longer support Visual Studio Tools for Apache Cordova, as detailed on this page. So I followed the advice on that page to migrate things to Visual Studio Code. This wasn't too hard, I just followed the instructions here. It does take a while to (re)install and/or update everything on Windows and Mac, though.

Next, there was the issue of updating to a newer version of Cordova. Luckily all the plugins that the app used were still supported, so I could remove the old versions of the plugins and install newer versions easily:

cordova plugin remove plugin_name
cordova plugin add plugin_name

This was pretty much all that was needed to generate a new Android version. Now, for the iOS, there were some additional issues. Apple wants apps to migrate from UIWebView to WKWebView, and hence newer versions of cordova-ios have been migrated to WKWebView. This has several consequences:

  • WKWebView enforces use of CORS. This required config changes to allow access to local files. The following needed to be added to config.xml:
    <preference name="scheme" value="app" />
    <preference name="hostname" value="localhost" />
  • CORS even required some changes to the remote web service that the app used. Additional headers needed to be specified there (Access-Control-Allow-Origin and Access-Control-Allow-Headers in my case) to make sure XHR requests were performed.
  • LocalStorage was in a different location due to the webview migration. This required installation of a plugin to migrate it: cordova-plugin-migrate-localstorage. However, this plugin can't be installed with cordova-ios 6.x, because it requires the plugin cordova-plugin-wkwebview-engine which is obsolete and doesn't work anymore. Luckily here I found a solution where someone installed a fork of this plugin which doesn't require cordova-plugin-wkwebview-engine. One does need to edit this plugin's file migrateLocalStorage.m and replace
    #define TARGET_LS_FILEPATH @"WebKit/WebsiteData/LocalStorage/http_localhost_8080.localstorage"
    with
    #define TARGET_LS_FILEPATH @"WebKit/WebsiteData/LocalStorage/app_localhost_0.localstorage"
    and then it kind of works.
Phew.