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

Categories

0 votes
537 views
in Technique[技术] by (71.8m points)

objective c - 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

See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)
+ (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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...