iOS, Delete all data saved to device by app using

2019-09-21 09:54发布

问题:

I want my app to delete all the information it has saved to the device, and i was told you do this using the NSFile Manager, so i was wondering what the code was to do this?

回答1:

Simple ,

folderPath is the path of your Document Directory.

   NSString *folderPath;

NSArray *dirContents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:folderPath error:&error];  
        for (NSString *strName in dirContents) {                        
                [[NSFileManager defaultManager] removeItemAtPath:[folderPath stringByAppendingPathComponent:strName] error:&error];      
        }

Hope it will be helpful to you