nax_
nax_

Reputation: 469

deleting image I've saved before exiting the program

I'm creating an app that uses pictures from the camera.

I ask the user to take a picture then save it in my document folder. It appears that it is not deleted when the program exits.

How and where is this best done (appdelegate perhaps)?

Upvotes: 0

Views: 292

Answers (2)

Ankit
Ankit

Reputation: 4710

If you want to get the files deleted when application exit, I would recommend you to use the /tmp directory instead. Read the documentation of File System.

Also if you just want to delete the files in documents directory, do it from applicationWillTerminate as follows:

    NSArray *homePaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *homeDir = [homePaths objectAtIndex:0];

    NSFileManager *fileManager = [NSFileManager defaultManager];

    NSError *error=nil;

    NSArray *contents = [fileManager contentsOfDirectoryAtPath:homeDir error:nil];

    for (NSString *file in contents) {
        BOOL success = [fileManager removeItemAtPath:[homeDir stringByAppendingPathComponent:file] error:&error];

        if(!success){
            NSLog(@"couldn't delete file: %@",error);
        }
    }

Upvotes: 1

Max
Max

Reputation: 16719

Delete your picture in

 - (void)applicationWillTerminate:(UIApplication *)application

of you app delegate;

Upvotes: 0

Related Questions