ios - Solution For Monitoring and Maintaining App's Size on Disc -
I am creating an app that uses extensive CoreData and many of my models have UIImage and NSData properties ( For images) and videos). Since this is not a good idea to store the data directly into the coredata, I have created a file manager class that writes files in different buckets of documents, depending on context and the type of media type.
My question is now how do I manage the document directory? Is there any way to find out how much space the app has used from its total allocated space? In addition, what is the best way to go about cleaning those directories; Whether files are written every time or only on app launches, check them on the Act.
Find out how much space the app has used from its total allocated space What is a method?
The application does not have the total assigned space limit, they are limited to the amount of space on the device. To scan the directory, you can find out how much space you are using for these files by using NSFileManager
. There are several ways in which to do different ways - see enumerator atpath:
for example. For each file, use a method like attributesOfItemAtPath: error:
to get a file size.
Creating and deleting files will have to track better file sizes. Keep running total, stored in user defaults. When you create a new file, increase it by the amount of new data when you extract a file, then subtract the total running.
In addition, what is the best way to go about cleaning those directories; Whether files are written every time, or only on app launches, check on the Act Act.
If these files are local data that are a natural part of the respective core data objects, then the sensible approach is to delete a file when its core data object is removed. Managed objects require a data file, so if you still use the object, do not delete the file. This means there should be a way to link to two, but I believe it is already true because you say that these files are used in any way by managed objects.
If the files are like cached data that are easily re-created or re-downloaded, you should place them in the space returned by NSTemporaryDirectory ()
. Then iOS can remove them when it thinks that space is needed. Scans old files by scanning for old files or for those who have not been used in a while (these details how you use files).
Comments
Post a Comment