美文网首页
iOS 检测手机总可用存储空间

iOS 检测手机总可用存储空间

作者: 春鹏 | 来源:发表于2017-05-05 09:48 被阅读0次

    最近项目中用到视频下载,下载过成中需要检测磁盘空间大小,如果可用储存空间太小就提示终止下载。

       /// 总大小
        float totalsize = 0.0;
        /// 剩余大小
        float freesize = 0.0;
        /// 是否登录
        NSError *error = nil;
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSDictionary *dictionary = [[NSFileManager defaultManager] attributesOfFileSystemForPath:[paths lastObject] error: &error];
        if (dictionary)
        {
            NSNumber *_free = [dictionary objectForKey:NSFileSystemFreeSize];
            freesize = [_free unsignedLongLongValue]*1.0/(1024);
            
            NSNumber *_total = [dictionary objectForKey:NSFileSystemSize];
            totalsize = [_total unsignedLongLongValue]*1.0/(1024);
            
            NSLog(@" totalsize %f G,freesize %f G",totalsize/1024.0/1024.0,freesize/1024.0/1024.0);
        } else
        {
            NSLog(@"Error Obtaining System Memory Info: Domain = %@, Code = %ld", [error domain], (long)[error code]);
        }
    
    

    相关文章

      网友评论

          本文标题:iOS 检测手机总可用存储空间

          本文链接:https://www.haomeiwen.com/subject/poeftxtx.html