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.
Thanks to Max Maier and Roman Barzyczak. Updated to Swift 3, using URLs instead of strings.
func clearTmpDir(){
var removed: Int = 0
do {
let tmpDirURL = URL(string: NSTemporaryDirectory())!
let tmpFiles = try FileManager.default.contentsOfDirectory(at: tmpDirURL, includingPropertiesForKeys: nil, options: .skipsHiddenFiles)
print("\(tmpFiles.count) temporary files found")
for url in tmpFiles {
removed += 1
try FileManager.default.removeItem(at: url)
}
print("\(removed) temporary files removed")
} catch {
print(error)
print("\(removed) temporary files removed")
}
}