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 stringWith开发者_如何学GoFormat:@"%@",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.
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 returnsYES
. Otherwise this method returnsNO
.
NSFileManager *fileManager = [NSFileManager defaultManager];
[fileManager removeItemAtPath:pngFilePath error:NULL];
精彩评论