• 如何获得iphone设备的剩余空间


    在手机终端开发的时候,我们需要关注手机剩余空间,因为手机不像电脑一样空间宽裕,当设备空间比较少得时候需要释放空间.

    用法:先引入头文件   

    #include <sys/param.h>  

    #include <sys/mount.h>

    代码片段:

    + (long long) freeDiskSpaceInBytesByMB{

        struct statfs buf;

        long long freespace = -1;

        if(statfs("/var", &buf) >= 0){

            freespace = (long long)(buf.f_bsize * buf.f_bfree);

        }

        return freespace/1024/1024;

    }

    先来说说statfs这个东东,这是C语言函数,下面是官方的介绍:

    #if __DARWIN_64_BIT_INO_T

     struct statfs __DARWIN_STRUCT_STATFS64;

    #else /* !__DARWIN_64_BIT_INO_T */

    /*

     * LP64 - WARNING - must be kept in sync with struct user_statfs in mount_internal.h.

     */

    struct statfs {

    short f_otype; /* TEMPORARY SHADOW COPY OF f_type */

    short f_oflags; /* TEMPORARY SHADOW COPY OF f_flags */

    long f_bsize; /* fundamental file system block size */

    long f_iosize; /* optimal transfer block size */

    long f_blocks; /* total data blocks in file system */

    long f_bfree; /* free blocks in fs */

    long f_bavail; /* free blocks avail to non-superuser */

    long f_files; /* total file nodes in file system */

    long f_ffree; /* free file nodes in fs */

    fsid_t f_fsid; /* file system id */

    uid_t f_owner; /* user that mounted the filesystem */

    short f_reserved1; /* spare for later */

    short f_type; /* type of filesystem */

    long f_flags; /* copy of mount exported flags */

    long    f_reserved2[2]; /* reserved for future use */

    char f_fstypename[MFSNAMELEN]; /* fs type name */

    char f_mntonname[MNAMELEN]; /* directory on which mounted */

    char f_mntfromname[MNAMELEN];/* mounted filesystem */

    char f_reserved3; /* For alignment */

    long f_reserved4[4]; /* For future use */

    };

    #endif /* __DARWIN_64_BIT_INO_T */

      

    永远保持新人的心态,勤奋好学,不耻下问
  • 相关阅读:
    jaxb解析xml工具类
    JQuery的父、子、兄弟节点查找方法
    jw player 配置参数
    jQuery判断当前元素是第几个元素&获取第N个元素
    正则表达式中test,match,exec区别
    php常用函数file
    php常用函数time
    php常用array函数
    php常用string函数
    Linux常用命令
  • 原文地址:https://www.cnblogs.com/keepFlying/p/4479497.html
Copyright © 2020-2023  润新知