It is enough to check the place on the iphone device before downloading files

right now i can successfully upload deleted files,

but this is only if the user can select one file, if the user selects several file names and click "Download". Therefore, before downloading files, I want to check if there is enough space on the iphone, if so, then download, and if not, then the user can see the message “there is not enough space” and he will turn off several file names, and then he will be able to download files from the server ...

Is there a way to check the free space before downloading?

early

+7
source share
2 answers

Use this function:

#include <sys/param.h> #include <sys/mount.h> +(float) diskSpace { NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); struct statfs tStats; statfs([[paths lastObject] cString], &tStats); float total_space = (float)(tStats.f_blocks * tStats.f_bsize); return total_space; // for freespace: // float free_space = (float)(tStats.f_bavail * tStats.f_bsize); // return free_space } 
+8
source
 + (long long)getFreeSpace { long long freeSpace = 0.0f; NSError *error = nil; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSDictionary *dictionary = [[NSFileManager defaultManager] attributesOfFileSystemForPath:[paths lastObject] error: &error]; if (dictionary) { NSNumber *fileSystemFreeSizeInBytes = [dictionary objectForKey: NSFileSystemFreeSize]; freeSpace = [fileSystemFreeSizeInBytes longLongValue]; } else { //Handle error } return freeSpace; } 

Use this code to query the file system for free space.

+19
source

All Articles