Quick Tip: Auto-include Open-Source Acknowledgements with CocoaPods

Open-source software is so prolific that it's likely nothing written today doesn't include some in one form or another. Keeping track of the licenses and acknowledgements that need to be included when working with multiple dependencies can be tricky. CocoaPods does a great job of managing the dependencies themselves but as it turns out it can also help us including those acknowledgments in our app.

Settings Bundle

As you probably already know a Settings Bundle is the way we add settings to iOS's global Settings app. It's essentially just a plist or collection of plists and handily CocoaPods generates a plist containing acknowledgements for all used pods that we can automatically include here.

If you haven't already, create a Settings Bundle for your project from the new file panel.

Create a Settings Bundle

Once created you'll see a Settings.bundle appear in the navigator panel on the left of Xcode. Inside are two files, a Root.plist and the accompanying strings file that will be used for any translations required.

A fresh Settings.bundle

While we're here we'll make the changes required to the Root.plist file. We're going to add an option that will take users to a second screen that will display the information provided to us by CocoaPods.

Create a new item in the Preference Items array, set its Type to Child Pane, the Title to Open Source (or whatever you wish it to be), and the Filename to OpenSource. This is going to be the name of the child plist file we're gonna copy over from CocoaPods in a moment.

The completed Root.plist

New Run Script Phase

Within your project's Build Pases create a new Run Script Phase and name it something like "Copy Acknowledgements". In the phase, paste in the following replacing the placeholders.

cp "${SRCROOT}/Pods/Target Support Files/<PODTARGET>/<PODTARGET>-acknowledgements.plist" "${SRCROOT}/<PATHTOBUNDLE>/Settings.bundle/OpenSource.plist"
  • <PODTARGET> is the name of the target you've installed CocoaPods to. For example, it may be Pods-Fetch or Pods-Facebook.
  • <PATHTOBUNDLE> is the location of the Settings.bundle file within your project.

The next time you build/install your app the acknowledgements from CocoaPods will be automatically included in your app's settings.

CocoaPods settings acknowledgements

CocoaPods have more information about the generated files on their wiki and also include information on using a post-install hook instead of the above run-script phase.