How to access all the files(pdf, doc etc) in iOS? - 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 :)

Related

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.

Xamarin iOS: What is different between Document Provider and Importing Document

I am new on iOS. In my application, I need to get files on the phone e.g. pdf, words etc in the phone. I know iOS application has their own sandbox to work with, they have no idea of other applications.
I have read some of the extension : Document Provider and a older post importing document through this link : https://mobiforge.com/design-development/importing-exporting-documents-ios
Is there any different between the two setup in my requirement? Sorry this is my first time working on iOS.
Unfortunately, iOS does not allows to share files storage between apps from two different developers.
If you own both apps, you can use App Groups to share data and files between apps. You can read more about App Groups, and how to use the APIs here https://developer.xamarin.com/guides/ios/watch/working-with/app-groups/

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.

Specific constraints of iOS sandboxing

I would like read access to the files in the iPhones music directory:
~/Media/iTunes_Control/Music/F**/*.{M4A,MP3}
1) I can't seem to figure out from the docs whether iOS apps are sandboxed such that I would or would not have this permission.
2) Is it necessary to ask for read or write permissions to directories outside the iOS App sandbox ? Only write permissions ? How does one do this, or is it just up to the discretion of the team that reviews the App for app store release ?
3) I have found a lot of information in the apple docs on sandboxing of OS X apps but not of iOS apps. Is there a similar sandboxing/entitlements process for iOS as for OS X apps ? Any useful links I should read ?
Update: as accepted answer says below, 1,2, and 3 are impossible, however it is possible to obtain a copy of a file in the media library, which is in some sense equivalent to having read access to the original - because of course the digital information is identical. This question contains code that does that:
Application crashed while importing songs from Ipod library in Iphone for iOs 5.0
You will not have permission to read/write outside your application.
You will not have permission to read/write outside your application.
You will not have permission to read/write outside your application.
You can use the Media Player framework to access information about the user's library, but nothing using the filesystem.
Sandboxing on iOS is done for you, there is no need to set that up.
You can not write files outside your applications sandbox.
I have not attempted to access music stored by the iPod app, but there is access to media types. It functions much like access photos.
Here is the link to the Apple docs for MPMediaPickerController.

Does iOS have any equivalents to DLLs/IPC/process spawning?

Are separate apps able to share the same binary in a form like a DLL? I know its possible to compile static libraries but I wouldn't count these as the same as a DLL (i.e. a dll is one copy of a binary shared by multiple apps, whereas static libraries are separately included by any using app).
Is each app totally separate from each other, are there any IPC or file sharing mechanisms available for differing apps to communicate and share data?
Is it possible for an app to create a new process in addition to a new thread (I guess not)?
You can't share executable files between applications. Apple requires that all apps function standalone. However you can use a UIDocumentInteractionController to get another program to deal with files you don't understand, and a 'quick view' may be available. That's how Mail works, for example.
Programs from the same vendor can share the keychain and, I think, iCloud storage as of iOS 5, but can't share storage on disk. As they can declare supported file types, UIDocumentInteractionController can be used to push temporary access to a file from one app to another. A custom URL scheme can be used in a similar way to pass fragments of data if that helps.
As a general rule, only one user process may be active at once in iOS - e.g. background processing is essentially event based. So you can't create a second process for yourself.
You can do this if you are developing for a jailbroken phone. Not
otherwise.On jailbroken phones, you can create .dylibs or shared libraries that can be
loaded via the DYLD_INSERT_LIBRARIES environment var (much like on
MacOS)
Apps are sandboxed. However, there are some ways of communicating between apps. You can use
(a) customURL scheme (also mentioned by Tommy above)
(if any) associated with an app to launch an app and send some
parameters to the launching app
(b) If you control communicating
apps, then you can use Message ports (CFMessagePortCreateRemote)
(c) If you control communicating apps, you could use Darwin
NOtification center for distributed apps.
Of course the expectation for (b) and (c) is that the
communicating apps are all running. On iOS since there is only one foreground
process, you'd have to have the other as a background app and that's
restricted to certain kinds of apps on the iOS platform.
Basically, no to all of the above, unless you're targeting jailbroken phones and are bypassing Apple's App Store. If you jailbreak, I believe you have similar options to those you have in Mac OS X.

Resources