check enough space on iphone device before downloading files

前端 未结 2 1313
花落未央
花落未央 2020-12-13 23:04

right now i am able to download remote files successfully,

but this is only if user can select one file if user select multiple file names and press download. So bef

相关标签:
2条回答
  • 2020-12-13 23:49

    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
    }
    
    0 讨论(0)
  • 2020-12-13 23:52
    + (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 filesystem for available free space.

    0 讨论(0)
提交回复
热议问题