Opening files outside iOS Sandbox in a Delphi Firemonkey app

  

I am developing a kind of document viewer app with Delphi 10.4.
After finishing the Android version I now started with iOS, which works fine until I try accessing files outside of my apps Sandbox.
There are three options of opening files which I would all like to support:
1. The Files App:
I already managed registering my app as handler for the specific extension and opening files using the "copy to" option. This means that every time a user wants to open a document they have to search for my app in the sharing options which is really not intuitive. It also means, that the document is copied to my app’s directory every time and I would have to periodically clear everything or waste a lot of memory.
A better way is to use the "open in" option, which should grant my app access to the real file.
By itself this is no problem, but handling the request now becomes one.
I already found out that since I’m working outside of my Sandbox, the URL I get passed on is now security scoped and I have to "tell the OS" every time I want to actually access it either using startAccessingSecurityScopedResource() or by letting UIDocument handle everything. Both of these don’t seem to work with Delphi, I couldn’t find an implementation of startAccessingSecurityScopedResource() in the iOSAPI and UIDocument needs a NSUrl which cant be extracted from the Url I get passed on, since I don’t have access to it.
2. E-Mail Attachments:
This seems to be the easiest, the Attachment isn’t really saved anywhere in the accessible File System, so I just use the "copy-to" option. This still leaves the Problem of new files being created every time a user opens an attachment, but i guess just automatically deleting duplicates is going to be close enough…
3. My own ‘Explorer’:
The first plan was to just have a file explorer built into the app as I did for the Android version.
But after my Problems with the first two options, I think I can forget about the idea of iOS just letting me play around with paths to shared directories.
I found similar apps using a UIDocumentPickerViewController which I guess would be the best way to just find out the Url but this would on one hand still leave me with the problem of a security scoped Url like in Option 1, on the other hand I didn’t find any implementations of DocumentPickers or something similar in the iOSAPI anyways.
Are there any other ways to approach those Problems, or does Delphi just not support it?
I am using the following Versions:
Delphi 10.4 Sydney Patch 3
Platform Assistant Server 21.0
macOS Catalina 10.15.6
Xcode 11.7
iPhone 7 with iOS 13.7

Comments are closed.