views:

314

answers:

1

Hey there,

I'm building an app that allows a user to select or take a photo then it is saved as a jpeg to the app's documents directory. Everything works perfectly, however, I realized that each time I build and run the Xcode project on the device, in reinstalls the app thus creating a new documents directory path. Is there any way to retain the path each time the app is installed?

This is the code I'm using to generate the path to the document's directory for saving:

NSArray *thePathArray = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *finalPath = [[thePathArray objectAtIndex:0] stringByAppendingPathComponent:@"user_image.jpg"];

Is there a better way to do this? Can I use a relative path? Or is there no real solution since the entire app is reinstalled each time it's build via Xcode?

Thanks, Howie

+1  A: 

XCode does reinstall the app, but, the documents directory, library, and preferences are saved. It works similarly to the way the App Store updates your apps.

I think your problem might be that you are saving the file with the same name every time. The iPhone file manager does not append numbers for you, it just overwrites the existing file, you have to change the name yourself.

I would recommend appending a number to the end, and saving the current number you are on in NSUserDefaults.

On a side note, unless you want the user to be able to see the files you are saving to the documents directory, I would save your files to the Library. Currently, the iPad allows you to see the documents directory though iTunes and that functionality will be coming to iPhone/iPod touch with 4.0.

Brian515