Share Specific directory in app's Documents with Files app - ios

I created an iOS app with file manager that browses inside subfolder in Documents.
The folders in app's documents are:
Settings
Root
Tmp
trash
The app's file manager browses only inside "Root" folder. Other folders must be hidden to users and inaccessible.
I want to share the "Root" folder with Files App that comes with iOS, so I added the following keys in info.plist:
<key>UIFileSharingEnabled</key>
<true/>
<key>LSSupportsOpeningDocumentsInPlace</key>
<true/>
It worked, but all of the folders are exposed, I only want to expose "Root" folder.
Is it possible to share a specific folder in Files app ?
Thank you very much.

Before using file system of iOS, Please check the usage of different directories of the iOS file system.
You can refer this link: https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemOverview/FileSystemOverview.html
As per above link, apple has clearly mentioned that:
For Documents Directory : It clearly says that this directory should only contain files that you may wish to expose to the user.
If you want something that should not be exposed to User, then dont use Documents directory, instead use Library directory for this.
For Library directory: Use the Library subdirectories for any files you don’t want exposed to the user. Your app should not use these directories for user data files.
Here, see the following screenshot from above link, which says about which directory to use when?
In short, keep your root directories content in Document directory and move all other directory with their content to Library directory OR Library/Application Support Directory. So, your intended purpose will get fulfilled.

Related

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

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

Can images from a user's photos library moved to the Hidden folder from a third party application?

Photos Framework provides an API to move to folders. But, is there a way to change the status of an image to hidden, and thereby move it to the iOS Hidden folder and hiding it from the main photo gallery?
If you want to save some data privately so no other app could access it you probably need to save it into the app data container. This could be a /Documents folder for example. Take a look at FileManager class to work with file system.
Use this directory to store user-generated content. The contents of this directory can be made available to the user through file sharing; therefore, his directory should only contain files that you may wish to expose to the user.
The contents of this directory are backed up by iTunes and iCloud.
File system documentation

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.

Add MP3's to apps main bundle without updating

I have an app written in Swift that is similar to a soundboard. Currently I just have a bunch of mp3s in the apps main bundle. Is it possible to remotely add more mp3s into the apps main bundle and then change a variable in the code to account for the new mp3s? I want it so that I can dynamically add new mp3s without going through the whole app review process. Ideally a user would be able to open the app the next day and find that 15 new mp3s have been added without having to download an update. Is this a possibility?
You can’t write to the main bundle on iOS. Its contents are
cryptographically signed as a part of the App Store submission
process; modifying its contents would prevent the application from
running.
Reference from THIS answer.
And you can get more information from this post: File write with [NSBundle mainBundle] fails.
File System Programming Guide:
< Application_Home>/AppName.app
This is the bundle directory containing the app itself. Do not write
anything to this directory. To prevent tampering, the bundle directory
is signed at installation time. Writing to this directory changes the
signature and prevents your app from launching again.
< Application_Home>/Documents/
Use this directory to store critical user documents and app data
files. Critical data is any data that cannot be recreated by your app,
such as user-generated content. The contents of this directory can be
made available to the user through file sharing. The contents of this
directory are backed up by iTunes.
< Application_Home>/Library/
This directory is the top-level directory for files that are not user
data files. You typically put files in one of several standard
subdirectories but you can also create custom subdirectories for files
you want backed up but not exposed to the user. You should not use
this directory for user data files. The contents of this directory
(with the exception of the Caches subdirectory) are backed up by
iTunes. For additional information about the Library directory, see
“The Library Directory Stores App-Specific Files.”
You can read THIS if you want to write a file into document directory.
Hope this will help.

Which directories does iOS apps have permission to write and read from?

I know that the you have read permission to files in the /var/mobile/Library/Preferences directory, however you don't have read permission to some other directories located in /var/mobile/Library/.
Where can I find a list of the allowed paths to read and write from inside an app running as mobile user?
I don't care if it is allowed to access the directory, so it can be submitted to the app store, as it is for a jailbreak tweak I am making.
Copied from http://iphonedevwiki.net/index.php/Seatbelt section "Working around the sandbox":
Anything in the container itself (of course).
~/* except the Media and Library subfolders, which only the following directories are readable:
~/Media/DCIM/*
~/Media/Photos/*
~/Library/AddressBook/*
~/Library/Keyboard/*
~/Library/Preferences/*
Where ~ refers to /var/mobile

Resources