【问题标题】:Cordova - can you override plist NSPhotoLibraryUsageDescription values set by a plugin?Cordova - 你能覆盖插件设置的 plist NSPhotoLibraryUsageDescription 值吗?
【发布时间】:2019-06-06 05:12:14
【问题描述】:

TLDR; 使用 Cordova,有没有办法覆盖插件可能设置的任何 Info.plist 值,例如 NSPhotoLibraryAddUsageDescription? (即,也许有一个钩子?)


许多 Cordova 插件尝试配置 plist 值,例如 NSPhotoLibraryUsageDescription。例如:

    <config-file target="*-Info.plist" parent="NSPhotoLibraryAddUsageDescription">
      <string>Please authorize photo library to save pictures.</string>
    </config-file>

    <config-file target ="*-Info.plist" parent="NSPhotoLibraryUsageDescription">
      <string>Please authorize photo library to save pictures.</string>
    </config-file>

如果有多个插件这样做,我们最终会在platforms/ios/ios.json 中得到多个值,例如:

{
  "prepare_queue": {
    "installed": [],
    "uninstalled": []
  },
  "config_munge": {
    "files": {
      "*-Info.plist": {
        "parents": {
          "NSPhotoLibraryUsageDescription": [
            {
              "xml": "<string>Send photos in your messages to the app.</string>",
              "count": 1
            },
            {
              "xml": "<string>We allow you to send us photos via our in-app messenger</string>",
              "count": 144
            }
          ],
           ...

这是有问题的,因为 Cordova 似乎只会将任何键 (NSPhotoLibraryUsageDescription) 的 last 项的值复制到 Info.plist 文件中。

另一个问题是在config.xml 中自己设置这些设置不会优先于插件设置的设置。这仅取决于 platforms/ios/ios.json 中的 last 值。

所以这里有两个问题:

  1. 插件可以提供错误的描述(例如cordova-plugin-x-socialsharing 插件),Apple can reject you for

    那么你就无法覆盖我所看到的这一点。

  2. 如果多个插件为同一个 Info.plist 值提供了一个值,则只使用最后一个。这对我来说是个问题,因为你无法真正控制哪个是“最后一个”。

所以我的问题是 - 在 config.xml 或钩子中有没有办法提供将使用的实际 Info.plist 设置?

(我目前使用的是 Cordova CLI 8.1.2)

【问题讨论】:

    标签: ios cordova cordova-plugins info.plist cordova-cli


    【解决方案1】:

    您可以使用cordova-custom-config 覆盖已由 Cordova 插入的使用说明消息: 由于cordova-custom-config 将其更改(默认情况下)应用到 Cordova 的 after_prepare 钩子上,因此它将在之后执行,因此其更改将优先。

    将其安装到您的项目中:

    cordova plugin add cordova-custom-config
    

    然后在你的config.xml 中定义一个&lt;custom-config-file&gt; 块,例如:

    <custom-config-file platform="ios" target="*-Info.plist" parent="NSPhotoLibraryUsageDescription">
        <string>My override description</string>
    </custom-config-file>
    

    注意:cordova-plugin-x-socialsharing 确实提供了一种机制来覆盖其自己的默认描述 - 它 defines &lt;preference&gt;s 可以在插件安装期间使用变量覆盖,例如:

    cordova plugin add cordova-plugin-x-socialsharing --variable PHOTO_LIBRARY_ADD_USAGE_DESCRIPTION="Some description" --variable PHOTO_LIBRARY_USAGE_DESCRIPTION="Some other description"
    

    【讨论】:

    • 太棒了,谢谢。我不知道cordova-custom-config。啊,是的,cordova-plugin-x-socialsharing 的这些变量是在我向项目报告此问题后的前几天添加的 :-)
    猜你喜欢
    • 2017-12-09
    • 2019-06-18
    • 2016-11-30
    • 2022-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多