Wednesday, June 08, 2011

Fix Exploded Folders on the iPhone

One feature of the Apple iPhone that I really like is the ability to group apps into 'folders'. You can put any app in any folder and rename it to whatever you like. I use this to organise apps according to their main purpose, such as 'music', 'games', 'social media', etc. It's really handy and definitely helps to cut down the clutter. The down-side is that it takes quite a while to create and populate these folders, but it should only be a one-off job. Right?


However I've had a problem that, according to online forums, appears to affect many people yet nobody seems to have described a good approach to resolving it. It involves syncing the iPhone with iTunes. Specifically syncing of Apps. Now and again (more often than not), syncing apps would cause all my carefully organised folders to 'explode'. Essentially, the folders are emptied into the main icon area, and removed. This is incredibly annoying.

There seem to be several different circumstances that lead to this 'explosion', but one circumstance is definitely reproducible - this is where you move your 'syncing' to a new computer. I just happened to have one, so I wanted to sync my iPhone with this computer, a perfectly natural thing to do. But as soon as I'd tick the 'sync apps' option, my folders would explode. Fortunately, this time, I observed that if I unticked the option immediately, my folders would be restored. If I click 'apply' or 'sync' I'm sure that would be the end of that.

Another situation involves adjusting folder contents on the device itself. The next time you sync with iTunes, there's a good chance you'll lose your folders.

So, to cut a long (8 hour) story short, this is what I did to enable app syncing and retain my beautiful folder structure.
  1. use iTunes to create a 'backup'.
  2. iTunes only keeps the last backup, so we need to ensure we 'capture' this for use later.
    1. make a copy of the backup directory (on OSX it's in ~/Library/Application Support/MobileSync/Backup) with a new timestamp. Something slightly different will be fine.
    2. edit Info.plist to change the Display Name key to something easily recognisable.
  3. Now we can restore this backup via iTunes (using the name set above) if we need to get our folders back. Unfortunately this also undoes the 'sync app' setting, so if you use this backup you will be back to square one.
  4. now we need to back up the Icon settings. There may be an easier and cheaper way to do this (such as using ssh to locate and scp to back up SpringBoard's IconState.plist file) but here's what I did:
    1. jail-broke my device (I used greenpois0n, on iOS 4.2.1)
    2. use Cydia to purchase PKGBackup (US$8)
    3. use PKGBackup to back up to Dropbox, specifically you want to back up the IconState.plist file
  5. Now I went back into iTunes and turned on 'sync apps'. Of course, my folders exploded, but I expected it this time. I synced and, yep, exploded folders. However now iTunes and the iPhone are talking to each other.
  6. (iTunes will have performed another backup before this sync, overwriting the last, which is why we made a manual backup in step 2)
  7. The last step is to use PKGBackup again to restore IconState.plist. This is the only file I restored (although a file called metadata insisted on coming along for the ride).
  8.  After the restore completed and the iPhone rebooted, I had all my folders back! Yay!


As a side-effect, I'm also using PKGBackup to back up everything else that the iTunes 'backup' omits - which is mostly everything. Useful program.

LifeHacker's guide to PKGBackup