My app allows users to take a photo and store it on their phone in order to refer to it later on. I have stored other user information in a plist, and am trying to do the same to the images. After the camera takes the picture, the UIImage is converted into NSData (using UIImagePNGRepresentation) and stored in the plist. The only problem is that after two or three images are stored, the app receives a memory warning and crashes. I would greatly appreciate if someone could tell me a more efficient method to store the images in the plist. Thanks in advance.
Asked
Active
Viewed 1,112 times
0
-
you should provide us more detailed information such as the code while you are saving. – kkocabiyik Jan 05 '14 at 00:34
-
The most efficient method of storing images in plist is not to store images in plist. – Petro Korienev Jan 05 '14 at 00:34
-
you need to post your code – Nick Jan 05 '14 at 00:40
2 Answers
1
I suggest you dont save the image to the plist, save the image to your Documents folder and the path to that image in the plist.

Refael.S
- 1,634
- 1
- 12
- 22
-
-
see http://stackoverflow.com/questions/2037432/saving-image-to-documents-directory-and-retrieving-for-email-attachment – Refael.S Jan 05 '14 at 00:46
-
@Rafael.S i'm still receiving a memory warning and the app is still crashing – user2430463 Jan 05 '14 at 17:11
0
You can use/try save on filesystem, every app in iOS is sandbox and has access to his own document folder.
what i suggest to write on filesystem and save the urls on the database as that is more performant than saving blobs on a database.
Apple has a good write up about the iOS filesystem.
Or
if You are cannot/won't to save anything inside the app's bundle. you can use +[NSData dataWithContentsOfURL:]
to store the image in your app's documents directory
NSData *imageData = [NSData dataWithContentsOfURL:myImageURL];
NSString *imagePath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:@"/myImage.png"];
[imageData writeToFile:imagePath atomically:YES];
or
useful link save-and-get-image-from-plist
helpful link how-to-store-an-image-path-in-a-plist