How to use LicensePlist to organise your settings bundle in iOS

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

Once CocoaPods and Homebrew have been installed you need to create a project and add some pods!Screen Shot 2017-11-08 at 22.22.59.png

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.

Screen Shot 2017-11-08 at 22.24.03.png
I find its handy to have “New Terminal at Folder” in my right click options. You can set this in Finder > Services, and selecting the “New Terminal at Folder”

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:

pod init

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.

Screen Shot 2017-11-08 at 22.30.08.png
I ended up adding SVProgressHUD after taking this screenshot!

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:

pod install

Now your pods will be downloaded for use in your project.Screen Shot 2017-11-08 at 22.30.56.png

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.Screen Shot 2017-11-08 at 22.31.17.png

Now your pods are installed, lets get to work implementing LicensePlist into your project!

Implementing LicensePlist

Earlier we installed Homebrew. Now we are going to use Homebrew to install LicensePlist for us.

$ 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…Screen Shot 2017-11-08 at 22.40.42.png

Now we can generate our custom license file from our pods. In the same directory we want to use the command

license-plist

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!Screen Shot 2017-11-08 at 22.41.22.png

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.

Screen Shot 2017-11-08 at 22.41.45.png

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.Screen Shot 2017-11-08 at 22.42.23.png

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.

Screen Shot 2017-11-08 at 22.44.37.png

Open it up and have a look…

Screen Shot 2017-11-08 at 22.44.51.png

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.Screen Shot 2017-11-08 at 22.45.05.png

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”.Screen Shot 2017-11-08 at 22.49.37.png

Next you will want to add a new row to the group/child pane, call this Filename (it should autocomplete for you)
Screen Shot 2017-11-08 at 22.50.15.png

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.Screen Shot 2017-11-08 at 22.51.06.png

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.Screen Shot 2017-11-08 at 22.51.51.png

You should be able to see the acknowledgements cell in the bundle, tap it to see all of your Pod acknowledgements neatly listed.Screen Shot 2017-11-08 at 22.52.00.png

And click any of these to view their licenses!

Screen Shot 2017-11-08 at 22.52.10.png

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!

You can find LicensePlist by Mono0926 on Github by following this link!

(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!

You can download the sample app used in this tutorial here

 

#LicensePlist #SettingsBundle #iOS #Swift #ObjectiveC #iOSTutorial #Carthage  #Cococapods

One thought on “How to use LicensePlist to organise your settings bundle in iOS

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s