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.
Swift 3 version as extension:
extension FileManager {
func clearTmpDirectory() {
do {
let tmpDirectory = try contentsOfDirectory(atPath: NSTemporaryDirectory())
try tmpDirectory.forEach {[unowned self] file in
let path = String.init(format: "%@%@", NSTemporaryDirectory(), file)
try self.removeItem(atPath: path)
}
} catch {
print(error)
}
}
}
Example of usage:
FileManager.default.clearTmpDirectory()
Thanks to Max Maier, Swift 2 version:
func clearTmpDirectory() {
do {
let tmpDirectory = try NSFileManager.defaultManager().contentsOfDirectoryAtPath(NSTemporaryDirectory())
try tmpDirectory.forEach { file in
let path = String.init(format: "%@%@", NSTemporaryDirectory(), file)
try NSFileManager.defaultManager().removeItemAtPath(path)
}
} catch {
print(error)
}
}