views:

193

answers:

2

I want to take a picture or select an existing picture from the users existing photos. What is the best way to do this?

Specifically I am concerned where I should to store the image. The storage location should be private to the application. I need to be able to reuse the image as a background every time the application opens. Thanks!

+3  A: 

You should use the UIImagePickerController to retrieve images from the library or the camera. You can persist the picture in the App's Documents folder. This folder is private to your app and is writeable.

Jasarien
+3  A: 

You can get the path to the documents folder like so

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

And to save a file there.

NSString *filePath = [NSString stringWithFormat:@"%@whatever.jpg",docDirectory];
NSData *toSave = UIImageJPEGRepresentation(image,1.0); //image is a UIImage
[toSave writeToFile:filePath atomically:YES];
Joe Cannatti