Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8705657
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:25:07+00:00 2026-06-13T03:25:07+00:00

I have an array which has pictures stored in it which are taken from

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T03:25:08+00:00Added an answer on June 13, 2026 at 3:25 am

    Instead of adding the image to an array why don’t you save the images to your app documents folder like this:

    //Save Image to Documents Directory
    UIImage *image = [info valueForKey:UIImagePickerControllerOriginalImage];
    NSString  *imagePath = [NSHomeDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"Documents/image.jpg"]];
    [UIImageJPEGRepresentation(image, 1.0) writeToFile:imagePath atomically:YES];
    

    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

    - (NSString *)currentDateandTime
    {
        NSDate *today = [NSDate date];
        NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
        [dateFormat setDateFormat:@"MMddyyyy_HHmmssSS"];
        NSString *dateString = [dateFormat stringFromDate:today];
        [dateFormat release];
    
        return dateString;
    }
    

    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:

    //Set Photo Date
    NSString *date = [self currentDateandTime];
    Now onto saving the image:
    //Save Image to Documents Directory
    UIImage *image = [info valueForKey:UIImagePickerControllerOriginalImage];
    NSString  *imagePath = [NSHomeDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"Documents/%@_image.jpg",date]];
    [UIImageJPEGRepresentation(image, 1.0) writeToFile:imagePath atomically:YES];
    

    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.  

    - (void)createPLIST
        NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documentsDirectory = [path objectAtIndex:0];
        NSString *plistPath = [documentsDirectory stringByAppendingString:@"/images.plist"];
        //Check to see if the file exists, if not create the file.
        if (![[NSFileManager defaultManager] fileExistsAtPath:plistPath]){
               //Creating empty Image Files Array for later use
               NSMutableArray *imageArray = [[NSMutableArray alloc] init];
               [imageArray writeToFile:plistPath atomically:YES];
           [imageArray release];
            }
    }
    

    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.

    - (void)createNewGalleryObject:(NSString *)date
    {
        NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documentsDirectory = [path objectAtIndex:0];
        NSString *plistPath = [NSString stringWithFormat:@"%@/images.plist", documentsDirectory];
        //Load PLIST into mutable array
        NSMutableArray *imageArray = [NSMutableArray arrayWithContentsOfFile:plistPath];
    
        //Create a dictionary for each image captured that saves basic information about the file for later use
        NSMutableDictionary *newEntry = [[NSMutableDictionary alloc] init];
        [imageArray addObject:newEntry];
    
        //This is where we write to the dictionary, it is up to you what values to save.
        //Based on what you told me I would save the information shown below.
        //For example Later you can do things like sort by date.
        [newEntry setValue:[NSDate date] forKey:@"Date"];
        [newEntry setValue:[NSString stringWithFormat:@"Documents/%@_originalImage.jpg",date] forKey:@"Original Image"];
    
        //Now save the array back to the PLIST, the array now contains a new dictionary object.
        //Every time you take a picture a new dictionary object is created
        [imageArray writeToFile:path atomically:YES];
        [newEntry release];
    }
    

    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.

    -(void)loadImages
    {
        //Load PLIST
        NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documentsDirectory = [path objectAtIndex:0];
        NSString *plistPath = [NSString stringWithFormat:@"%@/images.plist", documentsDirectory];
        //Load PLIST into mutable array
        NSMutableArray *imageArray = [NSMutableArray arrayWithContentsOfFile:plistPath];
    
        for (NSDictionary *dict in imageArray) {
        //Do whatever you want here, to load an image for example
           NSString *imageFilePath = [NSHomeDirectory() stringByAppendingPathComponent:[dict objectForKey:@"Original Image"]];
           UIImage *image = [UIImage imageWithContentsOfFile:imageFilePath];
        }
    }
    

    Rock on.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ImageView which shows a picture that has been taken from the
I have an NSManagedObject which has pictures that are stored somewhere like /var/mobile/Applications/.../.../uniqueIDforNSMO/Pictures/ I
I have an array which has many values in it . I just wanted
I have an array which has the contents as the result of an sql
I have created 4 buttons via Interface Builder. I have an array which has
I have an int array which has no elements and I'm trying to check
I have an array Items which has 10 elements. I need to remove the
I have an array called: $fragment = array($fragment); Which has the following three values:
I have a C++ code which has 3 array declarations. float A[NUM]; float B[NUM];
I have a file test.txt which has an array: array = [3,5,6,7,9,6,4,3,2,1,3,4,5,6,7,8,5,3,3,44,5,6,6,7] Now what

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.