0

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.

user2430463
  • 95
  • 1
  • 7

2 Answers2

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
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

Community
  • 1
  • 1
codercat
  • 22,873
  • 9
  • 61
  • 85