Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

check enough space on iphone device before downloading files

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 before downloading files i want to check is there enough space on iphone if yes then download and if not then user can see message box "not enough space" and he will uncheck few filename and then he can download files from server...

is there any way to check free space before downloading?

thank you in advance

like image 223
Pooja Avatar asked Mar 15 '11 10:03

Pooja


People also ask

How do I check my download space on my iPhone?

Go to Settings > General > [Device] Storage. You might see a list of recommendations for optimizing your device's storage, followed by a list of installed apps and the amount of storage each one uses. Tap an app's name for more information about its storage.

How much space do you need to download iPhone update?

Check that you have enough available storage In fact, you'll need a total of about 5GB of free space on your phone to download and install the update. To see how much free space your phone has right now, open the Settings app, tap General, and select iPhone Storage.


2 Answers

+ (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.

like image 57
Saurabh G Avatar answered Oct 11 '22 08:10

Saurabh G


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
}
like image 8
Max Avatar answered Oct 11 '22 10:10

Max