-3

I'm building a data which can store images into iOS document directory. I'm able to store the data in the document directory but how can I access it.And what is purpose of directory in iOS apps when there is persistent data store technologies like core data.Whether I can use directory to get persistent storage or I should go for core data.

Stark
  • 43
  • 5

2 Answers2

0

Have you tried using UIDocumentPickerViewController?

This is Apple documentation: https://developer.apple.com/documentation/uikit/uidocumentpickerviewcontroller

Here is a tutorial: https://medium.com/flawless-app-stories/a-swifty-way-to-pick-documents-59cad1988a8a

Lilya
  • 495
  • 6
  • 20
  • I use a image picker view to pick an image form gallery and iam able to store it in document directory but how can I access the image using files app is it possible? – Stark Jul 01 '20 at 11:26
  • @Stark please, see this answer: https://stackoverflow.com/questions/29005381/get-image-from-documents-directory-swift – Lilya Jul 01 '20 at 11:32
  • Yeah I was doing the same thing and I was able to retrieve the image but is it possible to access the images I have stored using files app in iOS – Stark Jul 01 '20 at 11:35
  • I'm getting the file path as /var/mobile/Containers/Data/Application/Documents/filename is it possible to acmes it outside the app using a file explorer app – Stark Jul 01 '20 at 11:38
0

I think, document directory is better solution in your case. Core data is useful for maintaining records corresponding to multiple fields.

Just use NSFileManager, something like this:

[[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:&error];
It will give you an array with all the file paths for all files in the given path.

This is how you load the images from the array of URLs.

NSArray *paths = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:&error];
for (NSURL *url in paths)
{
    UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:url]];
}
Ajjjjjjjj
  • 669
  • 4
  • 12
  • Same thing iam doing but is it possible to see where the image is stored and access it using files app in iOS – Stark Jul 01 '20 at 11:36
  • As a developer you can see where images are saved. you have to download the container You can open Organizer in Xcode and download the documents directory when your device is connected right ? – Ajjjjjjjj Jul 01 '20 at 11:39
  • your Application data can be shared with other App using only share Extension – Ajjjjjjjj Jul 01 '20 at 11:40