disk full error when writing big file and enable iCloud Photos

Hello~I want to ask a storage issue I had recently.

I found that my file writing will fail frequently if the iOS device enable iCloud Photos and the used storage is more than device storage.

ex. iCloud Photos 707.8 GB used and choose to optimize iPhone Storage
iOS Device UI shows that 185 GB is available (total 256 GB in device)

What I need is to write a big file to upload later and I use FileHandle to generate it:

ex.
let fileWriter = try? FileHandle(forWritingTo: url)
while !bufferIsAtEnd() {
   let data = readChunckFromBuffer()
   do{
      try fileWriter.write(contentsOf: data)
   }catch{
      return false
   }
}
fileWriter.close()

The file needs about 40GB space to write, but I always get disk full error even though iOS UI shows me the device space is enough ( 185GB )

This issue disappeared if I turn off iCloud Photos. I think that the available 185 GB seems to be locked by iCloud storage optimization(The total device storage 256GB is smaller than 707GB used in iCloud Photos) and makes my file writing failed.

I could not always turn off iCloud Photos since it is inconvenient but I do not know how to resolve the disk full issue when iCloud Photos enabled.

Any suggestion will be very appreciated!

Replies

Disk free space is a remarkably complex topic. One day I’ll write this up properly but, for the moment, lemme start you out with this link, which groups together all the properties available and an article explaining the basics.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"