your code looks fine, so try adding some "NSError" object to it:
- (void)removeImage:(NSString*)fileName { NSFileManager *fileManager = [NSFileManager defaultManager]; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *fullPath = [documentsDirectory stringByAppendingPathComponent: [NSString stringWithFormat:@"%@.png", fileName]]; NSError *error = nil; if(![fileManager removeItemAtPath: fullPath error:&error]) { NSLog(@"Delete failed:%@", error); } else { NSLog(@"image removed: %@", fullPath); } NSString *appFolderPath = [[NSBundle mainBundle] resourcePath]; NSLog(@"Directory Contents:\n%@", [fileManager directoryContentsAtPath: appFolderPath]); }
In the above code, I passed NSError
the removeItemAtPath error parameter. If the system cannot delete the file, this method will return NO
and fill the error
object with an error
.
source share