0

I just read through this link about ios file system. However, I still unable to decide how to properly store files in my app.

My app basically does the following.

  • display all sorts of files from the net. (docx, pdf, video, images, etc)

  • user can choose to save offline for the above files.

From the link, I think I have 3 directory choices.

  • Documents/ (recommended for user-generated or cannot be downloaded)

  • tmp/ (after done with files, should be deleted)

  • Library/caches (system will delete, but caches store longer than tmp)

So, my questions are,

  • where should I put if the user choose to save offline?
  • where should I put if the user decided not to save offline? I am using UIDocumentInteractionController

Also, I am a bit confused between cashes and tmp.

It would be nice if you can provide me sample code or link to tutorial blogs. Thanks!

Kyaw Htet Soe
  • 45
  • 1
  • 9
  • Apart from the offline function, what else do you do with the files? – Prerak Sola Oct 11 '17 at 09:46
  • **would appreciate, if you can provide me sample code.** -> This is not a coding service. You need to write your own code. – Prerak Sola Oct 11 '17 at 09:46
  • I just need to display them, the app is about, student viewing learning materials created by lecturers. – Kyaw Htet Soe Oct 11 '17 at 09:47
  • I am not asking to code for me, I am just saying it would be nice if you provide me sample codes, I just want to know the correct choice of directory to store my files – Kyaw Htet Soe Oct 11 '17 at 09:49
  • Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. – Prerak Sola Oct 11 '17 at 09:55
  • https://developer.apple.com/library/content/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/FileSystemOverview/FileSystemOverview.html it has all information you need there. You won’t get any answer more detailed than the link you already found. – Leo Dabus Oct 11 '17 at 10:32
  • 1
    thanks @LeoDabus, I found the links you provided useful! – Kyaw Htet Soe Oct 11 '17 at 11:01
  • @KyawHtetSoe you are welcome – Leo Dabus Oct 11 '17 at 11:19

2 Answers2

1

You should store downloaded files in /Documents if you want to display them in future. You should provide an option to delete them.

There is two well-written library to reduce your effort.

https://github.com/JohnSundell/Files by John Sundell

https://github.com/sketchytech/SwiftFiles by Anthony Levings

Milan Kamilya
  • 2,188
  • 1
  • 31
  • 44
0

For offline, you should store them in the Documents folder so that the system won't delete them automatically.

If there is no other use of the file, you should not download them at all.

Prerak Sola
  • 9,517
  • 7
  • 36
  • 67
  • Thanks for suggestions, but using UIDocumentInteractionController to display .ppt and .docx required the files is locally stored. If there are just videos, and pdf, I can use UIWebView and AVPlayer and no need to download, But .ppt, .docx, I need to save temporarily – Kyaw Htet Soe Oct 11 '17 at 09:57
  • For temporary storage https://stackoverflow.com/a/32657777/1433612 – Au Ris Oct 11 '17 at 10:01