Call CJT now on +44 (0) 1273 722 544 or contact us
Friday 3rd, September 2010

A little gotcha on Jailbroken iPhones

Posted by Tony Aldridge on June 19, 2009

One thing we’ve found in creating iPhone apps and running them on a Jailbroken iPhone to test them is that the directory fetching calls often return a different location from what you’d have in the simulator, or on an actual iPhone – and this target difference makes calls to file writing methods fail.

To get the Documents folder for your application, a typical place you’d want to write files, you’d call something like:

NSArray *paths = NSSearchPathForDirectoriesInDomains
(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *folderPath = [paths objectAtIndex:0];

And then would append your file name to the folder path for your calls to the writeToFile method.

Apple’s documentation states that these differ based on being in a Simulator or on an actual phone – on the phone:

/var/mobile/Applications/30B51836-D2DD-43AA-BCB4-9D4DADFED6A2/Documents

And on the Simulator:

/Volumes/Stuff/Users/johnDoe/Library/Application Support/iPhone Simulator/User/Applications
                                            /118086A0-FAAF-4CD4-9A0F-CD5E8D287270/Documents

However, with a Jailbroken iPhone, it tends to write in slightly less intuitive places – the version we’re using causes the call to return

/var/mobile/Documents

This directory doesn’t exist by default, so you’ll need to both create it, and also give permissions to it – this can be achieved through using mkdir and chmod

After that, your file writing should start working correctly!

2 Comments »

  1. Emanuele Cipolloni

    June 19, 2009 // 3:15 pm

    It is much easier if you use something like this:

    #define DOCSFOLDER [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]

    and then compose your paths like:

    NSString *filename_path = [DOCSFOLDER stringByAppendingPathComponent:@"myfile.ext"];

    Works in every situation, jailbroken or not, device or simulator, and you don’t rely on absolute array indexes or fixed values.

  2. Tony Aldridge

    June 19, 2009 // 3:37 pm

    It’s a cleaner way of getting the path, but the thrust of my post is about the folder not existing/not accessible on Jailbroken phones – when you get the home directory on a Jailbroken phone, regardless of method, it returns somewhere that an app isn’t naturally able to write to, so you’ll need to create and add rights to where it’s pointing.

Leave a Comment

Like what you see? Then get in touch;
t. +44 (0) 1273 722 544   e. contact us