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.
Related
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
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.
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.
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.
Does anyone have some sample code demonstrating how to make a "file browser" view? I'd like to be able to navigate through directories and drill-down the sub-directories and see files located within the various folders. I want the user to be able to create new directories/files and even select an existing file. Is there sample code out there already available to do this?
I don't know about sample code, but this wouldn't be too complicated to achieve using NSFileManager and a UITableView.
You can obtain arrays of directory contents using the subpathsOfDirectoryAtPath:error and associated methods of a file manager. These arrays in turn can populate a UITableView. It would be fairly easy to put together a navigation controller that could display a series of table views showing a file hiearchy.
Bear in mind, however, that you'll only be able to access the directories inside your application sandbox, unless you're running on a jailbroken device.
The iOS programming guide says that
You should never present users with the list of files in this directory and ask them to decide what to do with those files. Instead, sort through the files programmatically and add files without prompting.
This is assuming you are trying to implement file browse feature for your documents directory.
I'm an author of FileExplorer which is a file browser for iOS and fulfills most of your requirements.
Here are some of the features of my control:
Possibility to choose files or/and directories if there is a need for that
Possiblity to remove files or/and directories if there is a need for that
Built-in search functionality
View Audio, Video, Image and PDF files.
Possibility to add support for any file type.
You can find my control here.