如何删除一个iOS应用程序的tmp目录文件? [英] How to remove tmp directory files of an ios app?

查看:779
本文介绍了如何删除一个iOS应用程序的tmp目录文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用iPhone相机开发应用程序,经过多次测试,我意识到它将所有捕获的视频存储在应用程序的tmp目录中。
即使手机重新启动,捕捉也不会消失。

有没有办法清除所有这些捕捉,或者是否有任何方法可以轻松清理所有缓存和临时文件?

解决方案

是的。这个方法效果很好:

  +(void)clearTmpDirectory 
{
NSArray * tmpDirectory = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:NSTemporaryDirectory()error:NULL];
for(NSString * file in tmpDirectory){
[[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@%@%@,NSTemporaryDirectory(),file] error:NULL];
}
}


I'm working on an app that uses the iPhone camera and after making several tests I've realised that it is storing all the captured videos on the tmp directory of the app. The captures don`t disappear even if the phone is restarted.

Is there any way to remove all these captures or is there any way to easily clean all cache and temp files?

解决方案

Yes. This method works well:

+ (void)clearTmpDirectory
{
    NSArray* tmpDirectory = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:NSTemporaryDirectory() error:NULL];
    for (NSString *file in tmpDirectory) {
        [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@%@", NSTemporaryDirectory(), file] error:NULL];
    }
}

这篇关于如何删除一个iOS应用程序的tmp目录文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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