iOS, Delete all data saved to device by app using NSFileManager

♀尐吖头ヾ 提交于 2019-12-26 05:39:09

问题


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



来源:https://stackoverflow.com/questions/9358484/ios-delete-all-data-saved-to-device-by-app-using-nsfilemanager

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!