将字段添加到cordova ios应用程序中的info.plist

时间:2017-06-12 09:08:42

标签: ios angular cordova plugins

我需要创建自定义插件,为cordova / angular4 iOS应用程序添加info.plist条目。 (在这种情况下,如果按下主页按钮退出应用程序)

我需要添加行:

<key>UIApplicationExitsOnSuspend</key>
<true/>

以下是我写的插件内容(可能不正确,因为我无法对其进行测试)。

<config-file target="*-Info.plist" platform="ios" parent="UIApplicationExitsOnSuspend">
<array>
  <boolean><true/></boolean>
</array>
</config-file>

进口&#39;需要什么?这个插件到config.xml,所以每次我做cordova build ios plist文件都会有我需要的条目?

我已经阅读了这些帖子,但我并不了解它是如何完成的。

Add entry to iOS .plist file via Cordova config.xml

Cordova: Modifying *-Info.plist from plugin.xml

2 个答案:

答案 0 :(得分:2)

经过几个小时的搜索和几次尝试,实际上只需添加:

<config-file target="*-Info.plist" parent="UIApplicationExitsOnSuspend"> <true/> </config-file>

(在我的情况下阻止应用程序在后台运行)

直接进入 config.xml并将其嵌套在<platform name="ios">标记内,就像它是您的插件一样。此设置将在*-info.plist 期间添加到cordova build ios,而无需手动安装您的自定义插件。

提示:我首先误以为*target="*-Info.plist"而不是*必须有你的应用程序的标题,但实际上它必须是是<p>符号,cordova本身将为您的应用程序找出info.plist的名称。

答案 1 :(得分:1)

您应该在plugin.xml中添加此配置。

在ios平台内添加以下代码行:

<platform name="ios">
    <config-file target="*-Info.plist" parent="UIApplicationExitsOnSuspend">
      <true/>
    </config-file>
 </platform> 

让我知道它是如何运作的。

相关问题