Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
531 views
Welcome To Ask or Share your Answers For Others

1 Answer

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...