在iOS上的Temp目录中删除文件 [英] Deleting files from Temp directory on iOS

查看:507
本文介绍了在iOS上的Temp目录中删除文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个iOS应用程序,该程序可以从服务器上下载文件并将其存储在sql数据库中,稍后当用户单击消息时,它将解压缩文件并显示文件内容。

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.

为此,我编写了该函数,认为该函数适合我想做的事情:

For this purpose I wrote this function which I thought is right for what I want to do:

This是要从sql获取文件并将这些文件解压缩到临时文件夹

This is to get file from sql and unzip those files on temp folder

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

用户查看完此消息后,我将尝试删除此临时文件夹,因此当用户单击在下一条要显示的消息上,它在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).

我该如何解决此问题以及如何存储iOS上带有Temp文件夹的文件,并在用户使用完后清除p。

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.

推荐答案

检查文件是否存在:

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

这篇关于在iOS上的Temp目录中删除文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆