1

Just as we have UIImagePickerController to pick images into our iOS app. Is there a way to import the files in a similar manner as well? iOS 8 suggests a UIDocumentPickerViewController, but only for files in iCloud. Is there a way to import files in iOS 7?

Thanks!

Kaushil Ruparelia

Kaushil Ruparelia
  • 1,179
  • 2
  • 9
  • 26
  • What kind of files are you talking about? Because of the sandbox you are only allowed to read files in your own app sandbox. Normally the only interesting ones are that which the user created with your app or downloaded it with your app or whatever. All this files must be stored in the Document directory of your apps sandbox. So there is no need for a picker. You can just show the contents of this directory in a table view (f.e.) and let the user pick one. – Thallius Apr 15 '15 at 11:29
  • Files like the .txt and the .pdf. The way we are allowed to view the pictures and videos isn't there a way to get the URLs of those files as well? – Kaushil Ruparelia Apr 15 '15 at 11:48
  • No it isn't because there is no interchangeable directory every App can access. Thats the price we have to pay for the much more secure operating system. (I love it, that i must not think about installing a virus scanner on my phone) – Thallius Apr 15 '15 at 18:11

1 Answers1

1

iOS 8 allows you UIDocumentPickerViewController for picking files on iCloud. Other file inside your iDevice could not load or find with this controller.

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSString *documentsDirectory = [paths objectAtIndex:0];

NSFileManager *manager = [NSFileManager defaultManager];
NSArray *fileList = [manager contentsOfDirectoryAtPath:documentsDirectory error:nil];
for (NSString *s in fileList){
    NSLog(@"%@", s);
}

You can access files from your App Sandbox, and Some other type like, Images/Videos through UIImagePickerViewController.

In short, There is no way to get other files directly through any controller :(

HTH, Enjoy Coding !!

Viral Savaj
  • 3,379
  • 1
  • 26
  • 39