Reputation: 18305
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!
Upvotes: 1
Views: 301
Reputation: 5079
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];
Upvotes: 3
Reputation: 58458
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.
Upvotes: 3