How to add a plugin on only one Ionic platform?

Chris Rae picture Chris Rae · Apr 28, 2016 · Viewed 8.7k times · Source

I am using the excellent background geolocation plugin on an Ionic project. Unfortunately Apple don't think my usage is valid enough so I have to work out how to add this plugin only on Android. I can't fix this at a code level because the very existence of the plugin marks my app as requiring background geolocation in info.plist.

Is there a way in Ionic (perhaps in package.json) to flag a plugin as only to be installed on one particular platform?

Answer

liuwenzhuang picture liuwenzhuang · Apr 29, 2016

Maybe use plugman to add plugin for specific platform:
First,install plugman:

$ npm install -g plugman

And then, add plugin:

$ plugman install --platform <ios|android|blackberry10|wp8> --project <directory> --plugin <name|url|path>

for your situation, <directory> should be platforms/android, so the finally installation command is:

$ plugman install --platform android --project platforms/android --plugin https://github.com/mauron85/cordova-plugin-background-geolocation.git

More about plugman, refer to cordova plugman docs.Hope this will help, regards.