So I'm importing a file in my app with UIDocumentPicker
let documentMenu = UIDocumentMenuViewController(documentTypes: ["public.xml"], in: .import)
documentMenu.modalPresentationStyle = .formSheet
documentMenu.delegate = self
present(documentMenu, animated: true)
I don't have an extension for document management or anything like that. It's an xml. I just need to parse it and show the user the result. It's not editable, nothing to be saved, etc.
In the delegate method
func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) {
parseFor(path: url)
}
I can see the path points to a /tmp/ folder.
Printing description of url:
▿ file:///private/var/mobile/Containers/Data/Application/9C47C67D-B6F3-4E93-8239-52DCA93A6003/tmp/package.Inbox/file.kml
The question is: should I do anything about it, after the user is finished? I imagine if the file is in /tmp it will eventually get removed by the system.
Also, IF YES, how should I do it? Just save the path somewhere, and delete the file at that path?
Thanks!
From the docs regarding tmp/
:
Use this directory to write temporary files that do not need to persist between launches of your app. Your app should remove files from this directory when they are no longer needed; however, the system may purge this directory when your app is not running. The contents of this directory are not backed up by iTunes or iCloud.
So no, you don't have to do anything about it, since the OS will take care of cleaning up when your app is no longer running, at some undisclosed time.
However, if you know you are done with the file, it is generally good practice to delete it and free up space on the user's device. Deletion of the file works the same as deleting any file at a given path.