views:

372

answers:

2

Hi,

can some give me a good resource for the iphone filesystem? Basically I want to know:

  1. Where can I save my downloaded files into which folders? And which are not allowed?
  2. Which of these folders are hidden? (which won't be backup extracted) These files should stay on the device.

Want I'm trying to do is this: The user can download some videos from our server and watch it using our app. So I have to download the videos and save it somewhere on the iPhone, but I don't know exactly where to save these files so it won't be backup extracted.

First I tried ~/Documents folder, but the files in there will be extracted, so not an option for me.
Second I tried the ~/tmp folder. This folder seems to be working for me, because it wasn't extracted, but I don't know if this folder is always present? For how long will it persist? Because its called temp, will it be cleaned after some time/event?

If someone has information for me, I would really appreciate it.

Thanks in advice,
Buju

A: 

You need to read this:

Creating Paths and Locating Directories

All of it. Carefully.

Paul Lynch
thank you for your quick answer, but your link is about how to work with path in general. but what I need is, which folders I can use to save my files. I can't use `~/Documents` folder because iirc everything in that folder will also be extracted using a backup extractor and thats not an option for us.
Buju
You shouldn't be using paths directly, rather the returns from the functions mentioned in the docs. And the temp directory won't be backed up, as you have seen - and is indirectly referred to in the docs for such.
Paul Lynch
ah ok thx, i missed the part that there is already a function `NSTemporaryDirectory()` for getting the temp directory. I was just looking in the enum `NSSearchPathDomainMask` for `NSSearchPathForDirectoriesInDomains`, thats why I was a little confused. But isn't there a document which explains a little bit more about the usage of the Documents, Library, tmp, ... folders that will be created oppon installing the app? Something like: "always use Documents for saving files ..." or "never use tmp blablabla"?
Buju
If there is, I haven't seen one. There is a degree of overlap with MacOS X usage for the same functions, and a little study of the MacOS X file system might help - but iPhone uses its file system very differently, largely due to the different sandbox strategy.
Paul Lynch
Thank you very much. I was getting a little desperate at not finding such a document. I was thinking I was too stupid to search ;) But for now I will use the temporary folder for saving my files. Hope this works well.
Buju
+1  A: 

You might want to use <Application_Home>/Library/Caches.

From the apple docs @ https://developer.apple.com/iphone/prerelease/library/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/RuntimeEnvironment/RuntimeEnvironment.html#//apple_ref/doc/uid/TP40007072-CH2-SW12

Use this directory to write any application-specific support files that you want to persist between launches of the application. Your application is generally responsible for adding and removing these files. However, iTunes removes these files during a full restore of the device so you should be able to recreate them as needed.

sliver
Thanks! That was the answer I was looking for. How could I've missed that article.
Buju