Post

Replies

Boosts

Views

Activity

Displaying folder names from UIDocumentPickerViewController
I'm using UIDocumentPickerViewController to allow the user to select a folder in which to save a text file. All is working well except for being able to display a message confirming the location of the file saved. The screenshot (images not allowed here, so list of folders instead) shows a typical list of folders displayed by UIDocumentPickerViewController that the user can select: iCloud Drive Desktop Documents Documents by Readdle Downloads gjLists Shortcuts On My iPhone The folder names displayed to the user are those that are expected. However, the URLs returned by UIDocumentPickerViewController differ from those displayed and are not suitable for displaying to the user in a confirmation message: .../data/Library/Mobile Documents/com~apple~CloudDocs .../data/Library/Mobile Documents/com~apple~CloudDocs/Desktop .../data/Library/Mobile Documents/com~apple~CloudDocs/Documents .../data/Library/Mobile Documents/3L68KQB4HG~com~readdle~CommonDocuments/Documents .../data/Library/Mobile Documents/com~apple~CloudDocs/Downloads .../data/Library/Mobile Documents/iCloud~net~jermware~gjLists/Documents .../data/Library/Mobile Documents/iCloud~is~workflow~my~workflows/Documents .../data/Containers/Shared/AppGroup/EB502BF4-9272-466F-9F5D-0CA97E35E687/File Provider Storage In some of the URLs I could use just the last path component e.g. Desktop, Documents, Downloads, but for some it's the second from last path component e.g. gjLists, and for others the path is completely different e.g. Documents by Readdle, Shortcuts and On My iPhone. This makes it very difficult/impossible to reliably parse the URL to extract the folder displayed to the user by UIDocumentPickerViewController. After some investigation, I found the FileManager.default.displayName API which returns the display name of the file or directory at a specified path. This improves things somewhat, giving the following folder names for the above URLs: iCloud Drive iCloud Drive iCloud Drive Documents by Readdle Downloads gjLists Shortcuts File Provider Storage I now have the correct names for Documents by Readdle, Downloads, gjLists and Shortcuts, but just iCloud Drive for Desktop and Documents and still 'File Provider Storage' for 'On My Phone'. Does anyone know how, given the URLs returned by UIDocumentPickerViewController, I can get the folder name as displayed in the picker? Displaying a confirmation message to the user saying the file was successfully saved to the 'File Provider Storage' folder rather than 'On My iPhone' is going to cause no end of confusion.
1
0
656
Jul ’20