Apache Cordova 工具 (VS2015):将自定义条目添加到 *info.plist for iOS

Tools for Apache Cordova (VS2015): Adding custom entries to *info.plist for iOS

我在 VS2015 上使用 Apache Cordova 工具开发一个项目,我需要在 *info.plist 文件中设置一些额外的选项,以便暂时取消阻止 HTTP Web 访问 (NsAppTransportSecurity) 以及启用运行 在后台提供地理定位服务。

基本上,我需要添加以下...

<key>UIBackgroundModes</key>
<array>
    <string>location</string>
</array>
<key>NSLocationAlwaysUsageDescription</key>
<string>Location services are required.</string>
<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>

根据我对 Microsoft 文档 here, also referenced by the SO question 的理解,Apache Cordova 工具允许您将 *info.plist 文件添加到 /res/native/ios 文件夹以代替任何生成的文件。但是我无法让它工作。

上面的文档(在我看来)对于文件的命名有点混乱...

Place a custom Info.plist file in the res/native/ios/config.xml display name folder to override settings like splashscreens or icons. The Info.plist filename must be renamed as follows: config.xml display name-Info.plist to update iOS framework keys.

这是我认为可能出错的地方;我根本不知道文件名应该是什么。

给定 "My project" 的项目 "display name"(在设计器中查看 config.xml 时在 "Common Tab"、"Display Name" 上指定),我会假设文件名是 "My project-Info.plist" 或者可能是 "config.xml My project-Info.plist"。我也不确定是否应该创建另一个子文件夹来包含该文件...

Place a custom Info.plist file in the res/native/ios/config.xml display name folder

但是,无论我使用这些文件名中的哪一个,如果我在构建后在 Xcode 中打开项目(remotebuild/taco 子系统在 ~/. taco_home/remote-builds/taco-remote/builds/nnn/cordovaApp/platforms/ios/My 项目”文件夹,直到您关闭 remotebuild 服务器),然后查看随构建一起提交的 plist,我的设置不存在。

我还发现 "Platforms/ios/My Project" 文件夹中有一个 "My project-Info.plist",但如果我再次更改该文件副本,它们不会过滤到 Mac用于建筑。

任何人都可以验证我应该使用的文件夹和文件名。我知道我上面提到的 SO 问题是在 2 月份回来的,因此将一直指的是其中一个预览版本,并且知道项目的格式在那时和 RTM 之间发生了变化,这可能只是我遵循过时的指令。

谢谢。

好的,我终于搞清楚这是怎么回事了。给定上面 "My project" 的示例显示名称...

  • plist 文件应命名为 "My project-Info.plist"
  • 文件应该放在文件夹"res/native/ios/My project"

我想文档中对 "config.xml display name" 的引用确实有意义,因为它在设计器中查看 "config.xml" 时引用了公共选项卡中的 "Display Name" (尽管该元素实际上被命名为 "name")。我仍然认为这不是很清楚!

Note however that the file will be used instead of the generated file, and that any changes made to the config.xml will NOT be reflected in this file (you will instead have to replicate these changes manually).

因此建议您从可以在 "platforms/ios/{display name}/{display name}-Info.plist" 找到的原始文件的副本开始,或者坚持使用示例 "platforms/ios/My project/My project-Info.plist"。

您可以创建一个插件来执行此操作。这就是 plugin.xml 的样子:

<plugin ...> <platform name="ios"> <config-file target="*-Info.plist" parent="UIStatusBarHidden"> <true/> </config-file> <config-file target="*-Info.plist" parent="UIViewControllerBasedStatusBarAppearance"> <false/> </config-file> </platform> </plugin>

这是一个很好的参考: https://github.com/leecrossley/cordova-plugin-transport-security