如何删除ios应用程序的tmp目录文件?
我正在开发一个使用 iPhone 摄像头的应用程序,经过多次测试后,我意识到它将所有捕获的视频存储在应用程序的 tmp 目录中。 即使手机重新启动,捕获的内容也不会消失。
有什么方法可以删除所有这些捕获,或者有什么方法可以轻松清理所有缓存和临时文件?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
是的。这个方法效果很好:
Yes. This method works well:
Swift 3 版本作为扩展:
使用示例:
感谢 Max Maier,Swift 2 版本:
Swift 3 version as extension:
Example of usage:
Thanks to Max Maier, Swift 2 version:
Swift 4
可能的实现之一
Swift 4
One of the possible implementations
感谢马克斯·迈尔和罗曼·巴尔兹扎克。更新到 Swift 3,使用 URL 而不是字符串。
雨燕3
Thanks to Max Maier and Roman Barzyczak. Updated to Swift 3, using URLs instead of strings.
Swift 3
尝试使用此代码删除 NSTemporaryDirectory 文件
并检查数据删除或不在 didFinishLaunchingWithOptions 中写入代码
Try this code to remove NSTemporaryDirectory files
and to check data remove or not write code in didFinishLaunchingWithOptions
我知道我迟到了,但我想放弃直接在 URL 上运行的实现:
I know i'm late to the party but i'd like to drop my implementation which works straight on URLs, too:
这适用于越狱的 iPad,但我认为这也应该适用于未越狱的设备。
This works on a jailbroken iPad, but I think this should work on a non-jailbroken device also.
使用此专用代码删除所有 tmp 文件:
如果需要,可以在执行
forEach
之前过滤内容Use this dedicated code to remove all tmp files:
You filter the contents before performing the
forEach
if you need