升级到 Cordova ios6 导致项目 xcode 出错

Upgrading to Cordova ios6 causes errors in xcode for project

我能够在 ios5 中成功构建和 运行 我的应用程序,但是当我升级到 ios6.1.0 以安装允许我使用的插件时VKwebview 和引用本地 html 文件,我在 xcode:

中遇到 3 个致命错误
  1. 属性 'userAgent' 未在 'CDVViewController *'
  2. 类型的对象上找到
  3. 使用未声明的标识符'CDVUserAgentUtil'。 (重复两次)

我完全不知所措,甚至开始寻找答案。

这是我的 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="support@phonegap.com" 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>

CDVUserAgentUtilcordova-ios@6 中有 been removed,这是一个重大变化(因此主要版本从 cordova-ios 增加到 6)。 此 class 被您项目中的某些 Cordova 插件使用,因此出现错误。

您应该首先将所有插件更新到最新版本,以便使用那些已更新为删除对 CDVUserAgentUtil 的引用的插件。

至少你的插件之一 - 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 删除引用:

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

更新所有插件后,您项目中的其他插件可能仍然包含对 CDVUserAgentUtil 的引用。 如果是这种情况,您应该在其中搜索参考资料:

grep -r -l 'CDVUserAgentUtil' plugins/

如果您找到任何参考资料但没有可用的插件更新,您可以:

  • 针对要求更新的插件提出问题
  • 查找已更新的插件分支
  • fork 插件并自行修复

如果在更新所有插件以删除引用后构建仍然失败,则可能存在更多隐式引用,例如 cordova-plugin-file-transfer 中的隐式引用,因此您需要搜索并解决这些引用:

grep -r -l 'userAgent' plugins/

Cordova 中弃用了 cordova-plugin-wkwebview-engine iOS@6.x 更多详细信息 see,来自 Cordova iOS@6.x以后它默认支持 WKWebView 而不是 UIWebView。因此,您需要从您的项目中删除 Cordova 插件。

cordova plugin rm cordova-plugin-wkwebview-engine

注意:为了您的安全,请在进行任何更改之前备份您的项目。

对于 ionic v5 用户 我通过将 cordova-plugin-ionic-webview 升级到 4.2.1

来解决这个问题

跳过此帮助