0
我正在創建一個使用相機中圖片的應用程序。在退出程序之前保存的圖像
我要求用戶拍照,然後將其保存在我的文檔文件夾中。看起來程序退出時它不會被刪除。
如何以及在哪裏做得最好(appdelegate也許)?
我正在創建一個使用相機中圖片的應用程序。在退出程序之前保存的圖像
我要求用戶拍照,然後將其保存在我的文檔文件夾中。看起來程序退出時它不會被刪除。
如何以及在哪裏做得最好(appdelegate也許)?
如果你想讓應用程序退出時刪除文件,我建議你改用/ tmp目錄。閱讀documentation of File System。
此外,如果你只是想刪除的文件目錄中的文件,從applicationWillTerminate做到這一點,如下所示:
NSArray *homePaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *homeDir = [homePaths objectAtIndex:0];
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error=nil;
NSArray *contents = [fileManager contentsOfDirectoryAtPath:homeDir error:nil];
for (NSString *file in contents) {
BOOL success = [fileManager removeItemAtPath:[homeDir stringByAppendingPathComponent:file] error:&error];
if(!success){
NSLog(@"couldn't delete file: %@",error);
}
}
刪除你的照片
- (void)applicationWillTerminate:(UIApplication *)application
你的應用程序代理
;
您好,我只是試圖把我的照片在tmp目錄(似乎更好),但它不會在應用程序退出時刪除我的文件。這不是很奇怪嗎? – 2011-01-27 12:57:57