在下载文件之前,请检查iphone设备上的空间 [英] check enough space on iphone device before downloading files

查看:189
本文介绍了在下载文件之前,请检查iphone设备上的空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在我可以成功下载远程文件,但是只有当用户选择多个文件名并按下载时,才能选择一个文件。所以在下载文件之前,我想检查是否有足够的空间在iphone,如果是,然后下载,如果没有,然后用户可以看到消息框没有足够的空间,他将取消几个文件名,然后他可以从服务器下载文件...



在下载之前有没有办法检查可用空间?



提前谢谢你

解决方案

使用此功能:

  #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
}


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

解决方案

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
}

这篇关于在下载文件之前,请检查iphone设备上的空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆