Search code examples
iosswiftxcodemobile-application

What happens when you overflow iOS app Documents directory?


The mobile iOS app I am working on in Swift heavily relies on temporarily editing, encoding, and compressing videos and saving them in the Documents directory of the app, the sandbox so to speak. They need not be permanent as they are sent to my server to be shared with other users as messages.

All good things have limits, what is the size limit for the app Documents directory? If the limit is surpassed or the directory becomes full, will things be automatically deleted perhaps like a cache (first in last out)?

If it is not automatically handled, what is the proper way to ensure the Documents directory never becomes full?


Solution

  • From my experience of downloading huge amounts of data and pre-caching them in the app's bundle (not in the Documents directory though), there is no filesystem size limit that iOS imposes for the single app.

    The only limit is the free disk space of iOS device. Once you reach that limit, iOS triggers a cleanup on all the apps that are installed on the device, cleaning Library/Caches and tmp folders inside the bundle of all installed apps.

    I did not test this yet, but there seems to be an NSBundleResourceRequestLowDiskSpace notification that is posted by the system when free disk space gets low.