iShwar
iShwar

Reputation: 1665

How do I allow a user to browse/choose a file from device in iOS

I want to allow the user to upload the files in my iOS application just like the way we upload a particular file in desktop applications with browsing through the different directories. I did some googling too, but did not find the reliable solution.

Someone says that.

The whole file system is not available, if you're running a non-jailbroken phone. Neither are there filesystem browser controls (for the same reason), However, you can browse the user's photo library, or even take a photo with the camera using UIImagePickerController.

Some questions were like this

From these links and from other sources, I am only confused that can i provide the file browse option to user on button tap. And if yes, then how it can be achieved? Any help will be appreciated.

If the user taps on the Browse button the list should be there like

enter image description here

Upvotes: 7

Views: 8756

Answers (4)

Matt
Matt

Reputation: 910

Starting in iOS 8, you can use UIDocumentPickerViewController, "a view controller that provides access to documents or destinations outside your app’s sandbox":

https://developer.apple.com/documentation/uikit/uidocumentpickerviewcontroller

Upvotes: 3

Rafał Augustyniak
Rafał Augustyniak

Reputation: 2031

I'm an author of FileExplorer control which is a file browser for iOS. It allows you to browse files and directories that are placed inside your sandbox in a user-friendly way.

Here are some of the features of my control:

  1. Possibility to choose files or/and directories if there is a need for that
  2. Possiblity to remove files or/and directories if there is a need for that
  3. Built-in search functionality
  4. View Audio, Video, Image and PDF files.
  5. Possibility to add support for any file type.

You can find my control here.

Upvotes: 0

allprog
allprog

Reputation: 16780

There is no standard control for this purpose, but using the methods mentioned in the posts you referenced, populating a table view is perfectly doable. Keep in mind that this will allow you to view the files in your application's sandbox. You cannot access files of other applications.

Alternatively, you can use open source libraries like the ios_file_browser or the iOS-File-Browser. These provide user interface and you can check out the implementation as well.

Upvotes: 4

Anil
Anil

Reputation: 2438

iPhone apps are sandboxed. This means that you can only access files/folders inside your AppBundle (like Documents, Cache and the like). That is what the above mentioned URLs are suggesting. You can only upload/download data from/to these folders.

Now if you have a jailbroken phone, its a different scenario. Not going into that.

Check this link out:

Apple iOS Environment under that The App Sandbox

Upvotes: 7

Related Questions