Selecting "On My iPhone" folder in Files

I have an iOS app that allows user to select a folder (from local Files).

User is seemingly capable selecting the "On My iPhone" folder (the "Open" button is enabled, clickable and when it is tapped the app gets the relevant URL) although there's nothing in that folder apart from ".trash" item. Is selecting that folder not supported? If not why is the "Open" button enabled on that level to begin with?

nothing in that folder apart from ".trash" item

Clarification - what I meant to say: there are lots of items in that folder, just the app doesn't see anything but a single ".trash" item.

Filed a radar: FB19995978

How are you trying to access the URL? In what delegate method? Normally when you get a URL to a file outside your sandbox, the URL is only valid until the delegate method returns. Post some relevant code and clarify what APIs you are using.

Please see the code attached here..

Normally when you get a URL to a file outside your sandbox, the URL is only valid until the delegate method returns

That's not what I experience using the test app - it merely remembers the url in a variable and immediately returns from the delegate method, at some later point you could tap "start access" and afterwards "read" or "make bookmark", etc. this machinery itself works correctly.

If I were to guess: iOS doesn't want us to have an access to all app's documents (e.g. for privacy)... It's just having a possibility to select that root level makes things confusing.

User is seemingly capable of selecting the "On My iPhone" folder (the "Open" button is enabled, clickable, and when it is tapped, the app gets the relevant URL), although there's nothing in that folder apart from the ".trash" item.

Please file a bug on this and post the bug number back here once it's filed, as this is something we really should handle better.

If I were to guess: iOS doesn't want us to have access to all apps’ documents (e.g. for privacy)... It's just having the possibility to select that root level makes things confusing.

Sort of, but I don't think it's actually that intentional. I don't have time to test this at the moment, but if you experiment a bit, what I think you'll find is:

  1. If you directly create a file/directory in "On My iPhone", then your app will see that object.

  2. You can't see the "other" directories that are shown in "On My iPhone".

What's actually going on here is that what you're actually seeing when you look inside "On My iPhone" ISN'T actually "a directory", but is actually a collection of other directories being shown inside a single section. However, the confusing part is that there is a logical "root" directory (which is the directory you’re adding data to in #1), and that "root" directory is what you’re given when the user selects it. That creates the weird behavior where you only get access to a small subset of what the user sees.

Obviously, this is something that we could handle better (hence the bug above), but I think that's what's going on behind the scenes.

__
Kevin Elliott
DTS Engineer, CoreOS/Hardware

Selecting "On My iPhone" folder in Files
 
 
Q