Search code examples
iosnsfilemanager

how to detect existence of large file in iOS?


At runtime, my app downloads some large video files and plays them. They are large, so I figure they might get wiped at any time by the system trying to recover memory.

I had trouble using [fileManager fileExistsAtPath: pathOfVideo]:

Then I found an answer saying we should not use -fileExistsAtPath to determine if files exist.

The suggested solution is to open the file and see if it fails on opening. Even for 30MB files? I'm not so worried about race conditions here; the files are downloaded from the server and played in MediaPlayer. Should I still open the 30MB file to see if it exists instead of using fileExistsAtPath?


Solution

  • If you follow the links to the discussion of why one is advised not to use fileExistsAtPath (see Race Conditions and Secure File Operations), given the sandboxing of iPhone apps, it might be an acceptable risk.