1

I need to create custom plugin that will add entries to info.plist for cordova/angular4 iOS application. (In this case exit application if home button pressed)

I need to add row:

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

Here is the content of plugin I wrote (which may be not correct, because I couldn't test it).

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

What is needed to 'import' this plugin to config.xml and so that every time I do cordova build ios plist file will have entries I need?

I've read this posts and I didn't understood how it's done.

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

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

Stan Redoute
  • 1,733
  • 2
  • 16
  • 44

2 Answers2

4

After couple of hours of search and few attempts it was actually enough to just add:

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

(which in my case prevents application from running in the background)

right into config.xml and nest it inside <platform name="ios"> tag as if it was your plugin. And this setting will be added to *-info.plist during cordova build ios without any need to manually install your custom plugin.

Hint: I was firstly mistaken that instead of * in target="*-Info.plist" there has to be your app's title, but as it happens there actually has to be a * symbol and cordova itself will figure out the name of info.plist for you application.

Stan Redoute
  • 1,733
  • 2
  • 16
  • 44
1

You should add this configuration in plugin.xml.

Inside the ios platform add below lines of code:

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

Let me know how it works.

Avijit
  • 995
  • 10
  • 20
  • I have tried it and few variations already, nothing happens in .plist. Should I give just a name of .plist file as target, or relative path? – Stan Redoute Jun 12 '17 at 12:43
  • Hope you are installing the plugin through command line using `cordova plugin add ` – Avijit Jun 12 '17 at 13:46
  • I'm receiving Error: Registry returned 404 for GET on https://registry.npmjs.org/com.pmi.ca223 – Stan Redoute Jun 12 '17 at 13:54
  • How does config know that plugin should be run when building ios platform app? – Stan Redoute Jun 12 '17 at 14:01
  • I guess you are following standard procedure. When you install the plugin through command line in your Cordova project it will write the configuration values in the platform level .plist file. – Avijit Jun 12 '17 at 14:08
  • 1
    If you created a custom plugin in your local then follow this link to install https://stackoverflow.com/questions/30345035/how-to-add-a-local-cordova-plugin-with-ionic – Avijit Jun 12 '17 at 14:11
  • I don't use Ionic, or it is irrelevant in this situation? And how to make sure plugin is added to config every time build is done? – Stan Redoute Jun 12 '17 at 14:22
  • No not required. You can manually add a key in .plist file from Xcode. Build will not remove the key from plist. – Avijit Jun 13 '17 at 14:40