Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Saving file to tmp directory when iphone/ipad storage is full

Let's say an app downloads images from web while the user is browsing the app. Let's assume there are virtually unlimited images and a new image is downloaded whenever the user demands one. These images are saved to tmp directory for caching purpose. Once the user closes the app, all the images downloaded are deleted by the app.

Now, as there are unlimited images, what will happen if the user requests next image, the storage is full and the app attempts to save the image to the tmp directory?

Will the previous images be deleted by the iOS automatically to provide the space required for the new images? OR Will the iOS start cleaning tmp directory associated with other apps?(If yes, what happens when the storage is full again and such cleaning has already taken place for all the other apps?) OR Will the app crash?

like image 595
Mohit Singh Avatar asked Nov 10 '22 13:11

Mohit Singh


1 Answers

If you try and save a image to disk and the disk is full then NSData's

- (BOOL)writeToURL:(NSURL *)aURL
           options:(NSDataWritingOptions)mask
             error:(NSError **)errorPtr

Will return NO and an error object will be assigned to the errorPtr passed into the method. This error will have a NSFileWriteOutOfSpaceError. This error is very exceptional, and by the time you get it it's safe to say the system will have already notified the user that he is running out of disk space.

Having said that, a lot can be said about cleaning after yourself. If you're not going to use a saved image resource anymore then delete it from the file-system.

Cheers!

like image 199
Danny Bravo Avatar answered Nov 14 '22 21:11

Danny Bravo