3

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?

duan
  • 8,515
  • 3
  • 48
  • 70
Raj
  • 637
  • 13
  • 32

1 Answers1

2

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.

Woodstock
  • 22,184
  • 15
  • 80
  • 118
  • Hey thanks for your answer!! You are saying that user can not save files on his iPhone – Raj Mar 03 '14 at 07:48
  • @Raj - no problem, the user can save files (either generated in app or downloaded) - however you can only save these files to your apps sandboxed documents folder. It is a folder only visible by your application. You also need to write your own class/UI to present any 'saved' documents from this folder, as there is no general or system wide classes to allow you to interact with your applications documents folder. – Woodstock Mar 03 '14 at 07:52
  • ok, say I have downloaded the files from the web browser . So can I fetch this files in my app. – Raj Mar 03 '14 at 07:56
  • Sorry to ask such a silly questions but I don't know when I save any text or pdf file from browser where it is stored on iPhone. Like when we save image it is stored in Photos. – Raj Mar 03 '14 at 07:58
  • No. On iOS you have to think different ;). You don't open any file from your current app but instead go the application that "owns" the file and open it from there with your application (via a share button e.g.). – HAS Mar 03 '14 at 08:08
  • You can save files to your apps document folder using the NSFileManager Class, I have a link at the bottom of my answer above. – Woodstock Mar 03 '14 at 08:09
  • @Raj Updated my answer with iOS file system basics, please have a read . Let me know if your question is answered. – Woodstock Mar 03 '14 at 08:13
  • @HAS is there any framework which we can used to achieve what you have said – Manu Gupta Jun 20 '16 at 15:38
  • @ManuGupta This should be the normal ["Document Provider Extension"](https://developer.apple.com/library/ios/documentation/General/Conceptual/ExtensibilityPG/FileProvider.html#//apple_ref/doc/uid/TP40014214-CH18-SW1) behavior. – HAS Jun 20 '16 at 15:42