开发者

how to delete a image from iphone application

开发者 https://www.devze.com 2022-12-30 07:03 出处:网络
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.

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 returns YES. Otherwise this method returns NO.


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

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号