1

I want to save photo in Photo Library, but before this i need to know if there is enough free space to do it. How i can to know if there is enough free space to save my picture in Photo Library ?

My problem is that i need to download image from the server, but decision to do it includes if there is enough space in Photo Library application.

Thank you.

Ron Srebro
  • 6,263
  • 3
  • 22
  • 38
Alexander
  • 11
  • 2
  • Exact duplicate of http://stackoverflow.com/questions/1249014/iphone-available-disk-space and http://stackoverflow.com/questions/7618722/detect-no-disk-space-iphone-sdk and http://stackoverflow.com/questions/2606474/how-do-i-find-out-iphone-disk-space and http://stackoverflow.com/questions/5712527/ios-how-to-detect-total-available-free-disk-space-on-the-iphone-ipad-device – Polynomial Nov 13 '11 at 09:53
  • Possible duplicate of : http://stackoverflow.com/questions/178915/how-to-save-picture-to-iphone-photo-library – aleroot Nov 13 '11 at 09:53
  • I disagree, this is not a duplicate of any of the mentioned questions. Those question asks about general disk space on the device, while the question is specific about using the Photo Library (as opposed to the documents folder for the app). For more see my answer. – Ron Srebro Nov 13 '11 at 18:03
  • Are there good news with the PhotosFramework for iOS 8? Can we do this check prior to save? – Pichirichi Dec 25 '14 at 08:56

1 Answers1

3

I did some checking and it doesn't seem that Apple provide a way to check disk space when using ALAssetLibrary. They do however provide an error code, it the operation failed due to disk space issue.

I suggest you just try save the image and make sure you check the error returned in the completion block and notify the user accordingly.

ALAssetsLibraryWriteImageCompletionBlock has a NSError argument which can be one of the following

Error Codes AssetsLibrary-related error codes

enum {
   ALAssetsLibraryUnknownError =               -1,

   ALAssetsLibraryWriteFailedError =           -3300,
   ALAssetsLibraryWriteBusyError =             -3301,
   ALAssetsLibraryWriteInvalidDataError =      -3302,
   ALAssetsLibraryWriteIncompatibleDataError = -3303,
   ALAssetsLibraryWriteDataEncodingError =     -3304,
   ALAssetsLibraryWriteDiskSpaceError =        -3305,

   ALAssetsLibraryDataUnavailableError =       -3310,

   ALAssetsLibraryAccessUserDeniedError =      -3311,
   ALAssetsLibraryAccessGloballyDeniedError =  -3312,
};

If you want some additional checks before, you can use the method mentioned in the comments to find the available disk space on the device, but there's no guarantee AssetLibrary doesn't use different logic to calculate disk space requirements.

Ron Srebro
  • 6,263
  • 3
  • 22
  • 38
  • Unfortunately i didn't found any way to solve my problem and the one possible way is to try to save image and after this check error code, as you wrote ! Thank you, Ron. – Alexander Nov 15 '11 at 09:03
  • no problem. iPhone SDK isn't perfect. At this point though I think my answer should be accepted as an answer :) – Ron Srebro Nov 17 '11 at 17:30