Opening public iOS files using a Delphi FMX app - ios

I am developing a document viewer app that should be able to handle a custom file type. I already managed to resister my app as default handler for the file type using CFBundleDocumentTypes in my info.plist.
This enables me to choose a file from the explorer and open it in my app using the "copy to..." feature in the sharing options of the file.
The behavior of that feature isn't ideal for me, as it is not very intuitive for new users.
Also the files are (as the name already said) always copied to the internal Directory of my App, which changes their names and wastes a lot of space when opening the same file multiple times.
Adding LSSupportsOpeningDocumentsInPlace to the info.plist changes "copy to.." to be "open in..." which is also triggered by just tappin the file. On the iOS side this is exactly what I want, but now the URL my App receives is security scoped meaning I can't just access the File like one of my own.
The Apple Developer Documentation suggests either requesting Access by using startAccessingSecurityScopedResource() or by using the UIDocument class.
Both of which don't seem to work, I can't find any implementation of startAccessingSecurityScopedResource() in the iOSAPI and UIDocument needs a NSUrl which I can't create from the String "Url" which I get passed on when opening the App, since it is security scoped and can't be accessed.
Is there any other way to gain Access to security scoped Resources using Delphi or did I maybe miss something when looking through the iOSAPI?
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

Related

How to view document directory in iOS emulator?

I wrote a React Native application that downloads a file and saves it to the document directory.
The application gives me a path like this:
/Users/laurent/Library/Developer/CoreSimulator/Devices/SOMEID/data/Containers/Data/Application/SOMEID/Documents
and using macOS Finder I can see that the file has indeed been created.
My problem is how to view this file from the iOS emulator? If I click on the Files app for instance, I can't see that file. Basically is this file available to the user from somewhere and, if so, where? Or maybe I need to save it to a different directory?
Your iOS app is sandboxed by default, meaning that no other app can access its resources. The simulator is very different since it runs on your mac and stores your files there so you can easily access them.
That said, it is very simple to expose your Documents folder by adding the appropriate keys to your app's info.plist:
Add the UISupportsDocumentBrowser key to grants access to all the documents in the app’s Documents directory and have them appear in the Files app (iOS 11 and above). When this is enabled, other apps can also have access to your documents when using UIDocumentBrowserViewController.
Add the UIFileSharingEnabled key to expose the app’s Documents directory to the desktop iTunes app. When combined with the LSSupportsOpeningDocumentsInPlace key, it will also enable Files app support and document browser as mentioned above.
By default any files your application downloads are only available from within that app, they will not show up in the file system of the device.
As far as I know there is no react-native library which allows you to access the iOS file system, so you will need to make use of native iOS code to solve your problem. Besides pointing you to the official documentation, there is not much more I can do to help.

iOS, config files and sandboxing

My understanding is that because of sandboxing, it isn't possible to view any text file (ie config file) associated with an iOS app using another app. Something quite simple with Android. Am I mistaken?
I am trying to implement a text config file with a Unity iOS app that gets loaded and parsed once when the application boots.
This config file would also be able to be edited and saved manually on that actual iOS device.
(addendum)
In Unity there is PersistentDataPath which resolves to /var/mobile/Container/Data/Application/foo/Documents
Is there an iOS supported file explorer app that will allow me view and edit files in this location (without jailbreaking)?
Use can check iOS App Groups. It allows multiple apps access to shared containers and allow interprocess communication. There is no so much documentation about this, but maybe that's what you're looking for. At least you can share NSUserDefaults between the apps.
NSUserDefaults it's a most simple way to save any (not big) configurations for your app. For manual editing: if your app on the device signed with developer certificate, you can connect through any iOS supported file explorer app and edit it. But after release, from App Store, your app installed in restricted/private path, so it's not possible, if only you don't have a jailbreak.
Initial configuration you can put into your app bundle, and at the first run just copy them to NSUserDefaults.
Short answer: There are utilities such as iExplorer - https://macroplant.com - that allow "file manager" type access. However...
Long answer: If your app requires users to buy (or get) other software to modify configuration files, the chances of Apple approving it are slim to none.
The appropriate thing to do is to provide a User Interface in your own app which allows the user to modify / update the settings.

iOS File Retrieval - NSDocumentDirectory

I am working on a library with a very verbose logger module that, on iOS, writes xml logs to NSDocumentDirectory in a consistent file tree. I want to come up with a way for the user of this library to easily access these logs.
I know it is simple to programatically retrieve files from this directory, but is it possible to access this directory on an iOS physical device in any way from outside Xcode to retrieve these logs? I feel like I have seen it somewhere before, something in the manner of extracting the .ipa file and going into the package contents, but I could be wrong.
---------------------------------------------------------EDIT------------------------------------------------------------------
This (Browse the files created on a device by the IOS application I'm developing, on workstation?) is how to do it with Xcode on a device, but I have to assume that there is some way we can create that gets the logs off of a device for a user.
is it possible to access this directory on an iOS physical device in any way from outside Xcode to retrieve these logs?
It is possible to expose the Documents directory by enabling iTunes file sharing. When file sharing is enabled through this method, the contents of Documents directory would be visible to the user in iTunes, which can also be exported. The documents would also be visible for export through some third party desktop apps like iExplorer.
Here is the link to Apple documentation. You may also refer this thread to understand how this is done.
If you're using a simulator (apparently your task doesn't seem to need te real device) you are in luck.
You should go to a folder similar to this one:
/Users/[YOUR_USER_NAME]/Library/Developer/CoreSimulator/Devices/[RANDOM_HASH_YOU_SHOULD_DISCOVER]/data/Containers/Data/Application/[RANDOM_HASH_2_YOU_SHOULD_ALSO_DISCOVER]
Once there, with finder, you'll get the "documents" folder of the simulator and the app you're trying to retrieve your logs from.
You might say: I don't know which 2 RANDOM_HASHES should I go to.
Yes, you're right. If you have MANY simulators installed and or being used, it might be tricky to discover which one is the one you're trying to debug.
The same thing with your APP, your app will live in another RANDOM_HASH folder, and you should browse them, one by one, and then discover your documents folder.
Someone needed to solve this "mess" and created a Xcode Alcatraz Extension that leads you to the exact live simulator and APP you're debugging in any given moment, and then you don't need to guess which 2 random_hash paths you need to navigate to.
If Xcode + Alcartaz plugin extension manager is somewhat out of your reach, you might need to google it. It's not a difficult process.
PS: That magical Alcatraz Extension is named "XCodeWay" (in case you are brave enough to install Alcatraz onto your copy of XCode).
EDIT: Useful link to get Alcatraz: http://alcatraz.io/ Follow its easy instructions and you're done.
EDIT2: If Xcode cannot be used, then the last question in this other thread might come in handy: Browse the files created on a device by the IOS application I'm developing, on workstation?
(Still, an external application in your users machine will be needed )

File Manager equivalent on iOS?

I'm making a video decoder application on iOS using Xcode 4.2.
On click of a button I need to choose an input file to decode from a list of files.
Since there is no File Manager or File Browser on iOS, is there any way to go about this?
As others have pointed out, there is no iOS file manager. What there is the FileManager class. This class provides you the ability to:
get read-only access to items in your app package
get read/write access to your app's sandboxed container
You cannot access files elsewhere on the device, nor files belonging to other applications.
Some iOS applications (camera, pictures, contacts, etc) can be interacted with in a limited fashion by iOS API's that apple provides for that purpose. You can get more information about this in the apple developer docs online.
Thus, if your files are in your local app sandbox you can use FileManager to manually build a UI that allows users to see lists of the files there and pick one. They key being "you can build" on top of FileManager's functions for accessing the file tree.

Firemonkey app. needs data updates

I have a client database iPad/Iphone iOS application running OK. I wish to be able to easily update the data associated with the application and the ideal solution would be to read from a text file on my PC when I am connected to iTunes on my (Windows XP) PC.
Can my iPhone/iPad app open a file on my PC when connected to iTunes? I can't get a file path specification that will work (allow me to open a file on my PC).
I have also investigated the iTunes FILE SHARING facility, requires a manual modification to the application .PLIST file to turn this on. Since whenever I rebuild and "Export to XCode" my application a new .PLIST file is generated I have to manualy edit it each time to get the file sharing changes made so this seems to not be the answer.
Alternatively packaging the file with the iOS application would be workable. I get some sort of application checksum error if I drop the data file into the xCode application.. not sure why. I understood this was the mechanism to get the data file packaged with the project. Maybe I am dropping the data file in the wrong place...
Any help/suggestions would be appreciated.
Looks like the menu item Deployment under the Project drop down menu in XE2 does the job. Allows files, images etc to be packaged up with the application.

Resources