File Manager equivalent on iOS? - 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.

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.

How to access all the files(pdf, doc etc) in iOS?

How can I find out programmatically all the files present in iOS device and list them out to user? Also I need to download the file in my local application database?
How this can be achieved with Objective-C.
You cannot access all files in an iOS device outside the sandbox of the app. But there are other ways you can achieve this. What you can do is:
Access all the files in Gallery using UIImagePickerController.
Access all the user files in network- Dropbox/Google drive/iCloud. They all have separate public APIs that can be downloaded and used to download/upload files in network.
In this way, you can access most of the user files and use the same in your application.
Simple answer : you can't (on a non-jailbroken device).
Each app is launched is in own sandbox and can't interact with the others apps, expect using API provided by Apple for app-communication (ex: extension)
You should look at that Apple guide about App Sandboxing, which is valid for OSX and iOS apps.
The main difference between these two OS, as quoted directly from the doc :
iOS Note: Because it is not for user documents, an OS X container
differs from an iOS container—which, in iOS, is the one and only
location for user documents. In addition, an iOS container contains
the app itself. This is not so in OS X.
You cannot access all the files outside the app sandbox. But, if they are available at some shared location(network), you can use third party libraries to access them. For eg.
1. For iCloud- iOS provides inbuilt framework of UIDocument
2. For dropbox- DropBoxAPI is available
3. For Google drive- there is a separate library to access files in the drive.
Hope this helps :)

How to choose files from iPhone?

In my app I have to upload files to server.
For that I need to view and choose files from my iPhone and iPad. (any kind of files i.e pdf , doc,dock , mp3 etc etc).
How can I get the path for these files and how can I choose them in my application.
Generally in iPhone Where are these files are stored? how we can fetch them in our application?
Is there any thing like UIImagePickerController to pick file from iPhone?
There are classes that allow you to interact with various media types that may be on an iOS based device.
As you mention UIImagePickerController.
For music, you can use a similar class: MPMediaPickerControllerDelegate.
With regard to other arbitrary documents;
There is no device-wide document store, and you cannot access files stored inside another app's app bundle, thus you cannot access saved PDF/doc files. There is no shared place for the user to save such PDFs in the first place. Which is why media libraries have specific APIs to access them because they are device-wide libraries.
The most you can do is register your app as a viewer of PDF documents. This would allow other apps to open a PDF in your app if they use a UIDocumentInteractionController.
Your best option is probably to use File Sharing which will allow your application to own files on the device which can be synced via iTunes.
This will enable you to create your own UI, to present these files from your applications document folder.
Further reading: iOS File System Basics, File System Programming Guide.

How can you import text files into an iPad application?

For a school project, I am writing an iOS iPad application in which the user is capable of inputting sentences into core data that are used elsewhere in the system; however, my professor has now asked for another feature in which the user is capable of somehow entering sentences from some other interface than the iPad's keyboard. For instance, the most desirable solution is to be able to write sentences into text files and import them into the application through iTunes.
I have seen a few different apps capable of receiving files through iTunes, such as the VLC app in which the user can place videos into the VLC app's video storage. This allows VLC to then load the videos. I'm wondering if there is a good way or even if it's possible to do this with text files in my app, so that I may then read them into core data.
Thanks,
Chris
This is possible... First of all you need to add a value to your info.plist file which enables iTunes file sharing (like with VLC etc.) "UIFileSharingEnabled -> YES"
Then you can store files through iTunes. These files are put into your applications "Documents" - directory... When launching your application, you will need to check if new files are available and handle these changes...
You can also add document types / extensions, so that when you are sent an email with a txt file, it can be opened with your application. How do I register a custom filetype in iOS

Resources