How can I access the contents of a folder selected from Files app? - ios

Basically my app works like a iCloud-based note app (for example, logseq). Users first select a folder in Files app, then my app starts downloading/updating the contents of the folder.
So I implemented folder selection via UIDocumentPickerViewController, after I got the folder path in Files app. I tried downloading a hardcoded file like (<the folder path user just selected>/fileList.json) via FileManager.startDownloadingUbiquitousItem, got 257 permission error (the file does exist in my icloud drive). Then I followed the answer from this answer to call startAccessingSecurityScopedResource. It always returns false and the same 257 error returned.
Perhaps, I cannot access a random file from a selected folder? but how can those note apps work by simply letting users selecting a root folder?

Answering my own question after some debugging. Call startAccessingSecurityScopedResource on the folder path you grabbed from picker, not its subfiles. After that, you can start downloading its subfiles via startDownloadingUbiquitousItem

Related

Hyperlink to a file in the current folder regardless of its location on the drive

Putting together a .doc file with a table of content with links to external files. The challenge is: how to make them so that it points to the given file in the current folder regardless of its location on the disk.
Context: I will be sending the set of files to another person, so I can't put the path on my machine, nor on a server since they will be working offline. They will be working on Remarkable device and I want them to be able to use the major overview file with the links to access each of the files, rather than having to browse the folders.

Share multiple files via UIActivityViewController to Dropbox

My application works with HealthKit data in order to create some reports from the user's workout data and exports them to one or more files (mainly CSV and sometimes GPX files). To allow the user to access these files I present the standard UIActivityViewController passing as items an array of file as [URL] and no application activities (this is the relevant line in the code where files is the array of URLs).
It all works without issues, but today one of my users reported that when multiple files are exported and Dropbox is selected as the target for sharing the files, only the first one is saved and the others are ignored. Is there something I can do about it or is an issue that must be solved by Dropbox? To my understanding it should be the latter, but I can be missing something.
If they are relevant, here are two screenshot of the sharing screen under iOS 13: in the first only one CSV file is being shared and there's a Save to Dropbox option, in the second I'm sharing 2 CSV and 1 GPX files and that option is no longer there. In the second case there's still Copy to Dropbox (hidden) and it leads to only one file being saved, if I use Save to Files, all 3 files are correctly saved.
Marco,
You are right, this is a Dropbox issue, not an issue with your apps export. It looks like the Dropbox app, by default, only accepts one file when received from the export action. Here is the workaround. The native iOS Files app will accept multiple export files and it is possible to add the Dropbox folders to the Files app, effectively allowing the multiple files to be uploaded to Dropbox.
Adding Dropbox to Files app:
Open Files app, on the app main screen, click the three dots in the upper right corner, and select edit.
This will show a ghosted Dropbox file with a toggle switch next to it, tap to add Dropbox to the list of available files.
Exporting the Multiple Files to Dropbox:
Once steps 1 and 2 are complete, go to the desired export app, and select the file you want to export.
In the list of export options, select the iOS Files app (not Dropbox), and then select the Dropbox file within the Files app. Then you can select the Dropbox sub-folder you want the multiple export files to be placed in.
That accomplishes the desired goal in the same number of steps as exporting to DropBox.

How do I put content into the iOS Documents folder at compile time, using Xamarin?

I have a data file that I need to include with my app when I distribute it. When loading any files in the app, I prefix the file name with:
Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
This works great for anything I create within the app (and for reading back), like files I download in response to a user action. But I can't for the life of me figure out how to place files there when I build my app in Visual Studio.
I've tried making a "Documents" subdirectory in the special "Resources" folder, but that didn't work (I tried setting the "Build Action" to both BundleResource and Content). When I look at the folder for my app (from using the simulator) I can see that in the "Documents" folder there's all the files I downloaded, but I can't find my data file that I'm trying to bundle ahead of time. I even searched my entire hard drive on the Mac and still couldn't find said data file.
The data file isn't an image, if it matters. Just raw binary data. How do I set it up so that this file goes into the proper documents directory at compile time, so that I can read it using the SpecialFolder.MyDocuments prefix? Thanks.
You can't. You can include files in your app bundle, and then at startup copy them from the bundle into a user folder. But this won't happen automatically.

hidden files with .icloud extension in ubiquity container

I am building app which syncs documents over the iCloud.
When I create document (lets say its name is myfile1.doc) in one device and expect to appear in another one I get nothing - it looks like it doesn't sync. To my surprise when I read the content of Documents folder in ubiquity container I can see the representation of the file is added as a hidden file with .icloud extension (in this case .myfile1.doc.icloud).
I tried to find more about this .icloud files but so far no results.
Anyone know what are they representing? Is it the metadata item that indicates that file was added to iCloud and I should manually download it?
I think hidden files are handled by metadataQuery to indicate that the new file was added to iCloud and is waiting to be sync'ed. NSMetadataQuery recognizes them as representation of new files not yet downloaded to ubiquity container.
These files are not documented and you should ignore them. If you want to know what's in them, open one in a hex editor and have a look. Your code should not check for them or access them in any way.

Sample files in the documents folder after installing the app

is there a way that I can add sample files to the documents folder of an iOS-app before the app is actually started for the first time. For instance at install time.
For instance, I am writing a text editor and want to have a sample document, that the user can look at showing some of the features of the app. Could this sample be placed in some folder in Xcode and added to the documents folder automatically or do I have to add it from my code, the first time the app starts?
You can access files in sandbox.
Add some resources files. You can load them and save them the way you want.

Resources