Wednesday, June 11, 2014

iOS Settings Bundle With extra child panes

This tutorial is simply here to show you how to add in extra child panes into your iOS Settings.bundle. Please note that I have only done this with iOS and have no idea if everything will work for you in OS X. This tutorial is here since the great documentation from Apple stops, as it usually does, before showing the developer meaningful, more complex aspects of a feature.

For this tutorial, my project name is: SettingWithMore.  I mention that only so when you see that text you'll know what it is.

For this tutorial, I just created a simple single view application and then just added in the Settings bundle.  I did absolutely nothing besides that. i.e.: This is as simple as it gets.

So, what I did to get this to work:

1)  Added a settings bundle to my project.

  •     Right click -> New File -> iOS Resource -> Settings Bundle



NOTE: When creating/saving the settings bundle, I had to leave the name as "Settings" otherwise the settings, even leaving all the defaults untouched, never showed up in the emulator. This may or may not be the case for you, but I ran into the issue and it drove me crazy! In the image below, just pay attention to the text in the "Save As" text box.





  • When this step is complete, you'll have your settings bundle in your files under your "Project navigator." Be sure your bundle is part of/in the membership of the project.




2) Now you need to add in an additional property list.  This is just a standard property list.

  • Right click -> New File -> iOS/Resource -> Property List




NOTE: You can name this new property list pretty much anything you want. Don't name it info.plist! I named my new plist file "fooStuff.plist."

This new property list will be placed into your project - and here's my favorite part - you can't use Xcode to place it into your Settings Bundle. Though, Apple's documentation states that that is exactly what you need to do!




Off to the command line we go


3) You'll now manually copy your new plist file into your Settings.bundle directory.  I did this on the command line (you'll need to "cd" to your project's directory) - you can copy the new plist any way you feel comfortable - but all that needs to happen is that the new plist file needs to be placed into the Settings.bundle directory.


NOTE: As you can see I did a copy, which means the fooStuff.plist which was originally created still exists. I did it this way so nothing got mucked with in the Xcode project.  After I did this copy, I went back into Xcode and made sure the fooStuff.plist was in the Settings.bundle and then I deleted the original fooStuff.plist from within Xcode.  I did this just because I didn't want to risk Xcode freaking out.

You should now have a Setting.bundle which looks like this: (Just worry about the files under "Settings.bundle"




4) Now, to get things up and running, I took the easy way out -  I copied the "Root.plist" directly into my new "fooStuff.plist" file.  I closed all the files in Xcode (left the project open, just closed the files) and then went to the command line and executed: cp Root.plist fooStuff.plist

NOTE:  DON'T RUN YOUR APP YET - IT WON'T WORK YET!!!!!!!!!!

5)  Now you need to change one thing - you need the StringsTable String to be the same as your plist file name [without the extension].


NOTE: The top tag of "PreferenceSpecifiers" needs to be exactly like this.  Of course this isn't mentioned at all in the Apple documentation, and maybe it doesn't need to be.  However, if this wasn't named like this - I could NOT get it to work.  Once the naming was in place, it all magically worked.

NOTE:  DON'T RUN YOUR APP YET - IT WON'T WORK YET!!!!!!!!!!

6) And now finally - the last step: In the Root.plist file, you're going to add in a child pane and provide a file name.  Here's how:

  • So this was fun to figure out - What you need to do is go back into your original "Root.plist" file and add a row to the top level array and create that row as a dictionary.
  • Right click in your new plist file and select: property list type - > iPhone Settings Plist
  • Go back to the item you created and add in a "Type" and "Title"
  • NOW - select the arrows in the "Type" row and choose "Child Pane" - Place whatever name you want in "Title" but the "Type" key's value must be "Child Pane"  NOTE: Under the Type column, your "Child Pane" is  string.
  • Now right click your new item and select "Filename" for the new row.  The value for this type is going to be the name of your added plist file. In my case this was "fooStuff"  NOTE: DO NOT ADD IN THE "plist" EXTENSION!!!!!
  • I then added in one more row for "Key" because I use it in code. I put the same value as what I put in the "Title" row without any spaces.
Below is what my Root.plist file ultimately looked like:




Now you can run the app and see your settings.  From here, you can now easily go in and customize all your settings if you want extra textfields or anything else standard to the Settings.bundle.

NOTE: I had to clean and rebuild my project and reset my emulator before this ran and showed me all my settings.

IMPORTANT: If you copied the Root.plist into your new plist, as I did, be sure to go in and make all your rows' "Identifier" fields unique!


No comments:

Post a Comment