iphoneobjective-cuiimagensfilemanagernsfilehandle

How to save images and recorded files in temp directory?


I want to store pictures taken from camera and video recordings from my application in a separate folder in temporary directories for a while. And as the task is being completed, they shall be going to save into the database.

How do I save pictures taken from camera & video recording files in a separate folder in temp directories?


Solution

  • You are looking for this to get tot he caches folder to store temporary files:

    NSString* path = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, 
                                                          NSUserDomainMask,
                                                          YES) lastObject];
    

    From there you can use NSFileManager to create and remove the directories you want. And store files just as to any other part of a file system. Just be aware that the system will purge the caches directory now and then.

    So never rely on file remaining, nor disappearing, between restarts of your app.