Search code examples
xcodecordova

Upgrading to Cordova ios6 causes errors in xcode for project


I am able to successfully build and run my app in ios5, but when I upgrade to ios6.1.0 in order to install a plugin that will allow me to use VKwebview and reference local html files, I get 3 fatal errors in xcode:

  1. Property 'userAgent' not found on object of type 'CDVViewController *'
  2. Use of undeclared identifier 'CDVUserAgentUtil'. (these are repeated twice)

I am at a total loss as to even start looking for the answers.

This is my config.xml:

<?xml version='1.0' encoding='utf-8'?>
<widget id="com.slate.v2" version="1.3.1" xmlns="http://www.w3.org/ns/widgets" xmlns:gap="http://phonegap.com/ns/1.0">
    <name>ACCELERATE RMS</name>
    <description>
       M-learning accelerated.
    </description>
    <author email="[email protected]" href="http://phonegap.com">
        Cnnect
    </author>
    <content src="index.html" />
    <access origin="*" />
    <allow-navigation href="*" />
    <icon density="mdpi" height="57" platform="ios" src="icon.png" width="57" />
    <config-file overwrite="true" parent="NSCameraUsageDescription" platform="ios" target="*-Info.plist">
        <string>Allow the app to use your camera to take your profile picture.</string>
    </config-file>
    <preference name="AllowInlineMediaPlayback" value="true" />
    <preference name="AndroidPersistentFileLocation" value="Compatibility" />
    <platform name="ios">
        <preference name="WKWebViewOnly" value="true" />
        <feature name="CDVWKWebViewEngine">
            <param name="ios-package" value="CDVWKWebViewEngine" />
        </feature>
        <preference name="CordovaWebViewEngine" value="CDVWKWebViewEngine" />
    </platform>
    <platform name="ios">
        <preference name="Orientation" value="all" />
    </platform>
    <engine name="browser" spec="^5.0.4" />
    <plugin name="phonegap-plugin-contentsync" spec="~1.4.2" />
    <plugin name="cordova-plugin-camera" spec="~4.0.3" />
    <plugin name="cordova-plugin-geolocation" spec="~4.0.1" />
    <plugin name="cordova-plugin-file" spec="~6.0.1" />
    <plugin name="cordova-plugin-whitelist" spec="~1.3.3" />
    <plugin name="cordova-plugin-dialogs" spec="~2.0.1" />
    <plugin name="cordova-plugin-local-notification" spec="~0.9.0-beta.3">
        <variable name="ANDROID_SUPPORT_V4_VERSION" value="26.+" />
    </plugin>
    <plugin name="phonegap-plugin-barcodescanner" spec="~8.0.1" />
    <plugin name="onesignal-cordova-plugin" spec="~2.8.1" />
    <plugin name="cordova-plugin-file-transfer" spec="~1.7.1" />
    <plugin name="cordova-plugin-wkwebview-engine" spec="^1.2.1" />
    <plugin name="cordova-plugin-wkwebviewxhrfix" spec="~0.1.0" />
</widget>

Solution

  • CDVUserAgentUtil has been removed in cordova-ios@6 which is a breaking change (hence the major version increment in cordova-ios to 6). This class is used by some Cordova plugins in your project hence the error.

    You should first update all of your plugins to the latest versions so those which have been updated to removed references to CDVUserAgentUtil are used.

    At least one of your plugins - cordova-plugin-file-transfer is deprecated and contains an implicit reference to CDVUserAgentUtil. In this case you could use my fork of this plugin which has been fixed to remove the reference:

    cordova plugin rm cordova-plugin-file-transfer && cordova plugin add https://github.com/dpa99c/cordova-plugin-file-transfer
    

    It may be that other plugins in your project still contain references to CDVUserAgentUtil after updating all your plugins. If this is the case, you should search them for references:

    grep -r -l 'CDVUserAgentUtil' plugins/
    

    If you find any references and no plugin upates are available, you could:

    • raise an issue against the plugin asking for it to be updated
    • look for a fork of the plugin that has already been updated
    • fork the plugin and fix it yourself

    If the build still fails after updating all your plugins to remove the references, there may be more implicit references such as that in cordova-plugin-file-transfer so you'll need to search for and resolve those:

    grep -r -l 'userAgent' plugins/