Last updated on: May 27, 2023
We all have added a library we found on GitHub to our project to do our life more easier. But did you know most of these libraries comes with some rules who need to read before do anything with that?
This is called License or Copyright, to protect the developer of the library from unfair use from the people who use it. Usually, they are licensed under the MIT License or Apache License 2.0
And we need to add them to your app.
CocoaPods made it easier and saved us from that pain with Acknowledgements.
Today I’m going to saw you how to do it very easily without worrying about it anymore.
Let’s get started
We already have a ios project with pods installed, and the Podfile look like this:
Creating Settings Bundle
Now let’s go to our ios project create a folder called Resources by right-clicking on our project and choosing New Group:
After we gave it the name Resources to the folder, our project looks like this:
Now, right-click on the Resources folder and choose New File…
In the new window, in the Filter (top right corner) type settings, and choose Settings Bundle under the Resource section:
Then press Next and Create.
Setting up our Podfile
Now that we have created our Settings Bundle, we’re going to add the following code at the end of our Podfile:
# Uncomment the next line to define a global platform for your project # platform :ios, '9.0' target 'LibrariesLicensesExample' do # Comment the next line if you don't want to use dynamic frameworks use_frameworks! pod 'Alamofire' pod 'FLAnimatedImage' pod 'SDWebImage' # Pods for LibrariesLicensesExample end post_install do | installer | require 'fileutils' FileUtils.cp_r('Pods/Target Support Files/Pods-LibrariesLicensesExample/Pods-LibrariesLicensesExample-acknowledgements.plist', 'Resources/Settings.bundle/Acknowledgements.plist', :remove_destination => true) installer.aggregate_targets.each do |aggregate_target| aggregate_target.xcconfigs.each do |config_name, config_file| xcconfig_path = aggregate_target.xcconfig_path(config_name) config_file.save_as(xcconfig_path) end end endCode language: Swift (swift)
Replace the name ‘LibrariesLicensesExample’ with your app’s name in line 11
Now let’s update our pods by typing pod update in the terminal:
Let’s go and open our project again, and run the app
Hmmm… It seems that we don’t get the right results yet.
Let’s go to our Settings.bundle we created earlier, and choose the Root.plist file:
Go and delete all the item under the Preference Items array EXCEPT from Item 0, so we don’t have to create a new one again.
So the Root.plist now looks like this:
Now change the Type from Group to Child Pane
For the Title, we give the name Acknowledgements
NOTE: You can give other title if you want. Like ‘Licenses’, ‘Open Source Libraries’, ‘3rd Party Libraries Licenses’
And finally, we add one more row, by pressing the + button next to the Item 0, and we choose Filename from the dropdown menu and we give the value Acknowledgements
So, in the end, our Root.plist looks like this:
Let’s build our project and run it!
You can find the final project here
If you have any questions, please feel free to leave a comment below