1

In my app I want to download a big data file (maybe more than 50MB), but at the same time if the user has utilized lots of space in music and other things then how would the code get to know that the memory for the application is limited (for example 40 MB) and the code should now restrict the download.

dsgriffin
  • 61,907
  • 17
  • 128
  • 134
MPG
  • 241
  • 1
  • 13

2 Answers2

3

You can create a function to do so:

#include <sys/param.h>  
#include <sys/mount.h>  

+(float) diskSpaceLeft {  
    NSArray* thePath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);  
    struct statfs tStats;  
    const char *path = [[NSFileManager defaultManager] fileSystemRepresentationWithPath:[thePath lastObject]];
    statfs(path, &tStats);           
    float availableSpace = (float)(tStats.f_bavail * tStats.f_bsize);         
    return availableSpace;  
}
dsgriffin
  • 61,907
  • 17
  • 128
  • 134
0

use this:

 #include <sys/param.h>  
 #include <sys/mount.h>  

+(float) diskSpaceAvailable {  
    NSArray* pathDocDir = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);  
    struct statfs tStats;  
    statfs([[pathDocDir lastObject] cString], &tStats);  
    float total_space = (float)(tStats.f_blocks * tStats.f_bsize);  

    return total_space;  
}
Jonathan Day
  • 18,268
  • 7
  • 78
  • 135
Saurabh Singh
  • 249
  • 1
  • 6