I have an array which has pictures stored in it which are taken from the camera, but when the app is closed or minimised they are all gone next time the app is started. What is the best way to fix this?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Instead of adding the image to an array why don’t you save the images to your app documents folder like this:
Now you can always access the images anytime you are using the app.
Update #1:
Okay say you have more than one picture and you do not want to overwrite the images saved in your documents directory. I would do something like the following:
First create a method that returns the current date and time
As you can see the date is down to the millisecond, this prevents any chance of overwriting an image. To call the method see below:
By doing the above you have created a unique file name for the image. For example: 10212012_12182245_image.jpg
Now to retrieve the image. While you are saving the image you would also need to save the file name into a .PLIST file for example. You could create an array of the file names and save them to the disk as a PLIST file. Then you do things like sorting all the images by date or loading them by date.
Update #2:
Okay so you want to create and save to a PLIST. You can call this when the image picker loads.
Now you have created the PLIST, you will need to load it when saving images and then write data to it. I would suggest creating a separate method that gets called every time you snap a picture. What is going to happen is this: 1.) Take Picture 2.) Save Picture with date and time attached to the file name 3.) Pass that date object to the method below. The method below is going to add values to the dictionary and save the dictionary back to the documents directory. Also on a side note since we are saving everything to the documents folder all of the information is backed up so the user will not lose their images when upgrading the app.
Okay lets say you now have taken a bunch of pictures and stored the image information to your documents directory. You can do things like load all of the images in the array.
Rock on.