If you’ve ever installed and used an open source framework (through CocoaPods or Carthage) you have probably noticed that most of the frameworks come with an MIT license. This basically means that you can use the framework free of charge, so long as you mention it somewhere in your app. There are a few ways you can add acknowledgements to your app, this tutorial will focus on using License Plist by Mono0926 to create a tidy list of the pods you have used in your app.
Before we get started you need a few things installed to make this work! First you either need to have either CocoaPods or Carthage installed on your machine. I will be using CocoaPods in this guide, for Carthage users the basic process is the same and you should be able to follow along!
You can install CocoaPods by opening up the terminal and entering the following:
$ sudo gem install cocoapods
This command will do everything for you, just sit back and wait for the installation to complete. Next we need to install Homebrew :
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
should do it.
Adding Pods to your project
For this demo you won’t need a sensibly named project file, or even have to select a language. The process is the same for Swift and Objective C which is handy. Once you have created your project you will need to navigate to your project directory in Finder.
We need to add some Pods to our project so that they can be displayed. You can browse pods on the CocoaPods Website or look on somewhere like GitHub for a huge variety of open source frameworks. Lets create a pod file, once you have opened the terminal at your projects root directory you should enter:
Which will create a PodFile. Open the PodFile up with a text editor (I use TextMate) and add any and all of the pods you want to. For this example I will be using 4 pods: SVProgressHUD, SAMKeychain, DZNEmptyDataSet and SwiftierSwift.
Make sure to uncomment “use_frameworks” if you are using swift, it wouldn’t hurt uncommenting this line if you are using Objective C aswell. Also I usually set the platform to the latest version of iOS (currently 11) otherwise the pod install will shout at you!
Now you should have chosen some pods, lets install them. In the terminal (same directory) type:
Now your pods will be downloaded for use in your project.
Now you should close your Xcode project and reopen your project using the work space file generated by the Pods. You can’t access the pods if you don’t use the work space file, you will get used to working with work space files instead of project files if you regularly use Cocoapods.
Now your pods are installed, lets get to work implementing LicensePlist into your project!
$ brew install mono0926/license-plist/license-plist
This command will install the framework for us. This may take a while so be patient. If your installation is successful your terminal should look like this…
Now we can generate our custom license file from our pods. In the same directory we want to use the command
Which will generate our files for us. A new window should pop open with the generated files. Save this window we will need to use it later!
The Settings Bundle
We now have our Pod acknowledgements organised, all that’s left is to create a settings bundle and add our files to it.
You can create a settings bundle by going to File > New > File and scrolling down to Resource and select Settings Bundle. Make sure that the settings bundle is included within your project files, and that the build target membership is set to your app. Now lets drag the files we generated earlier into the settings bundle.
Lets have a go at building the app and see what happens…
When your app launches you want to press cmd+shift+h (which acts as pressing the home screen) to minimize the app. Find the settings app on the main screen and load it up. Scroll down to the bottom and you should see a menu item for your app.
Open it up and have a look…
So we have something in our bundle, its just not a tidy list of acknowledgements. That’s because we are currently using the settings bundle default template and haven’t actually told it to display our acknowledgements.
Go into the Root.plist file in the bundle and open up the “Preference Items” row.
This is the file telling the settings menu what to display. Delete all the entries except Group for now.
Add a new group to the list, we are going to use this to display the Pod acknowledgements generated by LicensePlist. The group should have 2 entries, Type and Title. On the far right column (value) click the drop down and change the type to “Child Pane”.
Next you will want to add a new row to the group/child pane, call this Filename (it should autocomplete for you)
Now we want to link the filename for our acknowledgements. This is the autogenerated name “com.mono0926.LicensePlist”, add this into the value field. While you are at it you should rename the Title to something useful, I’m using acknowledgement. The title is what the user will see when they open the settings menu.
Believe it or not but we are done, that was very easy wasn’t it!
Build and run your app, doing the same as before and navigating to the settings menu.
You should be able to see the acknowledgements cell in the bundle, tap it to see all of your Pod acknowledgements neatly listed.
And click any of these to view their licenses!
This is a really tidy way of acknowledging all of the third party frameworks you use in your project. I hope this guide was helpful!
(or manually: https://github.com/mono0926/LicensePlist)
If you find this library useful you should give it a star!
Thanks for reading and best of luck with your app!
#LicensePlist #SettingsBundle #iOS #Swift #ObjectiveC #iOSTutorial #Carthage #Cococapods