This problem has become much more complicated with the introduction of the Files app, and the "Open in place" feature.
If you do not have "Supports opening documents in place" switched on, in your info.plist
, then things are pretty much the same, and files opened from any other app still appear in the Documents/Inbox
directory. But files opened from the Files app appear in another inbox, currently at tmp/<bundle ID of app>-inbox
. It is still recommended to delete the file once you are done with it, but there is less need to occasionally clean the directory, because the tmp
directory gets cleaned by iOS once in a while anyways.
If you do have "Supports opening documents in place" switched on, then things change drastically. Files opened from the Files app and some other apps are no longer copied into an inbox, but they are passed to you at their original location. That is typically some location inside the Files app itself, inside another app referenced from the Files app, or even some general iCloud location. If you expose the files in your Documents folder, then it could even be one of your own app's files.
Needless to say, if you get such a file, you must not delete it. But if the file comes in an inbox, which will still happen a lot as well, then you must delete it. In order to determine this, the options of the application:openURL:options:
call contains an UIApplicationOpenURLOptionsOpenInPlaceKey
key. If that has value (NSNumber
) NO, then the file is in an inbox, and it should be deleted. It it has value YES, then it is opened in-place, and must not be deleted.
Note that for files that are opened in place, you also need to gain permission to use them first. You do that but surrounding the access to the file by startAccessingSecurityScopedResource
and stopAccessingSecurityScopedResource
calls. See Apple documentation for details.