简体   繁体   English

从iOS上的Temp目录中删除文件

[英]Deleting files from Temp directory on iOS

I'm writing an iOS application where im downloading files from server and storing it on a sql database and later when user click on a message it will unzip files and display content of the file. 我正在编写一个iOS应用程序,我从服务器下载文件并将其存储在sql数据库中,稍后当用户点击消息时,它将解压缩文件并显示文件内容。

For this purpose I wrote this function which I thought is right for what I want to do: 为此,我写了这个函数,我认为这是我想要做的:

This is to get file from sql and unzip those files on temp folder 这是从sql获取文件并在temp文件夹上解压缩这些文件

NSString *unzipFolder = [[CommonFunctions getCachePath]stringByAppendingPathComponent:@"temp"];

and once user done with viewing this message i'm trying to delete this temp folder so when user click on a next message to display it has space on temp folder, since function can always unzip files later-on to display 一旦用户完成查看此消息,我正在尝试删除此临时文件夹,以便当用户单击下一条消息显示它在临时文件夹上有空间时,因为函数总是可以在以后解压缩文件以显示

[[NSFileManager defaultManager] removeItemAtPath:unzipFolder error:&error];

My issue is When i run function to delete unzip folders content it doesn't delete this content and when user click on next item from message it display previous message images (Since they not cleaning up and auto replacing). 我的问题是,当我运行删除解压缩文件夹内容的功能时,它不会删除此内容,当用户点击消息中的下一项时,它会显示以前的消息图像(因为它们没有清理和自动替换)。

How can i solve this issue, and how can i store files on iOS with Temp folder and clean p when user done with it. 我如何解决这个问题,如何在iOS上使用Temp文件夹存储文件,并在用户完成后清理p。

Check if file exists: 检查文件是否存在:

if([[NSFileManager defaultManager] fileExistsAtPath:unzipFolder])
{
  NSError *error;
  [[NSFileManager defaultManager] removeItemAtPath:unzipFolder error:&error];
  NSLog@"Error : %@",[error description]);
}
else
{
  NSLog@"File Exists Not Exists");
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM