tags:

views:

63

answers:

2

I am working an iphone app where i am giving the option of downloading an image to user's iphone. Following is my code for downloading of image.

UIImage *image = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:urlAddress]]];
NSString *pngFilePath = [[[NSString stringWithFormat:@"%@/",docDir] stringByAppendingString:[NSString stringWithFormat:@"%@",couponID]] stringByAppendingString:@".png"];
NSData *data1 = [NSData dataWithData:UIImagePNGRepresentation(image)];
[data1 writeToFile:pngFilePath atomically:YES];

My above code works fine but now i want to give option of deleting the image downloaded from above code. Can some one please advice me how can i delete a image file from iphone.

+1  A: 
 NSFileManager *fileManager = [NSFileManager defaultManager];
[fileManager removeItemAtPath:pngFilePath error:NULL];
Kenny
thanks kenny it helped me
pankaj
+2  A: 

You use removeItemAtPath method http://developer.apple.com/mac/library/documentation/cocoa/reference/foundation/Classes/NSFileManager_Class/Reference/Reference.html#//apple_ref/occ/instm/NSFileManager/removeItemAtPath:error:.

NSFileManager *fileManager = [NSFileManager defaultManager];
[fileManager removeItemAtPath:pngFilePath error:NULL];

Return Value

YES if the removal operation is successful. If the operation is not successful, but the delegate returns YES from the fileManager:shouldProceedAfterError:removingItemAtPath: message, removeItemAtPath:error: also returns YES. Otherwise this method returns NO.

texmex5
thanks texmex, i have done it using using your help
pankaj