How to remove tmp directory files of an ios app?

前端 未结 6 996
囚心锁ツ
囚心锁ツ 2020-12-05 02:18

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.

6条回答
  •  青春惊慌失措
    2020-12-05 02:41

    Swift 4

    One of the possible implementations

    extension FileManager {
        func clearTmpDirectory() {
            do {
                let tmpDirURL = FileManager.default.temporaryDirectory
                let tmpDirectory = try contentsOfDirectory(atPath: tmpDirURL.path)
                try tmpDirectory.forEach { file in
                    let fileUrl = tmpDirURL.appendingPathComponent(file)
                    try removeItem(atPath: fileUrl.path)
                }
            } catch {
               //catch the error somehow
            }
        }
    }
    

提交回复
热议问题