- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
所以我正在尝试查找我的 iPhone 上的可用磁盘空间量,并且我已经搜索了几篇较旧的帖子。这些帖子中的大多数都使用 NSFileManager 来检索 NSFileSystemFreeSize 值。
但是,与我在手机设置>常规>关于>可用中看到的数字相比,NSFileSystemFreeSize 中的数字似乎不准确。
我得到以下这些值:
我使用的代码:
+ (NSString*)getFreeDiskspace
{
NSDictionary *atDict = [[NSFileManager defaultManager] attributesOfFileSystemForPath:@"/" error:NULL];
unsigned freeSpace = [[atDict objectForKey:NSFileSystemFreeSize] unsignedIntValue];
return [NSString stringWithFormat:@"%u", freeSpace];
}
其他信息:
谁能给我解释一下为什么 NSFileSystemFreeSize 与手机和 iTunes 不匹配?感谢任何帮助,谢谢!
最佳答案
有很多方法可以获得空闲空间
1、
NSString *tempDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSFileManager *fileManager = [NSFileManager defaultManager];
NSDictionary<NSFileAttributeKey, id> *att = [fileManager attributesOfFileSystemForPath:tempDir error:nil];
NSNumber *freeSize = att[NSFileSystemFreeSize];
const long long freeSpace = [freeSize longLongValue];
2、仅限iOS 11以上
NSURL *url = [[NSURL alloc] initFileURLWithPath:NSHomeDirectory()];
id AA = [url resourceValuesForKeys:@[NSURLVolumeAvailableCapacityForImportantUsageKey] error:nil][NSURLVolumeAvailableCapacityForImportantUsageKey];
NSLog(@"\nURLVolumeAvailableCapacityForImportantUsage : -----------\n%@", AA);
3、f_bavail或f_bfree供使用
- (const long long) diskSpace {
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
struct statfs tStats;
statfs([[paths lastObject] cStringUsingEncoding:NSUTF8StringEncoding], &tStats);
// for total space
// const long long total_space = (long long)(tStats.f_blocks * tStats.f_bsize);
// return total_space;
// for freespace:
const long long free_space = (long long)(tStats. f_bavail * tStats.f_bsize);
return free_space;
关于ios - NSFileSystemFreeSize 返回不准确的可用磁盘空间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48467776/
我在服务器启动时创建一个缓存(服务器启动每次都需要10分钟)。目前我正在使用内存缓存(Ehcache)。现在我想建立一个机制,以便一旦数据被缓存我应该能够在几秒钟内启动服务器。比如将缓存的持久副本写入
我编写 json 结构的方式使得文件(在进行了一个月的测量后)存储在磁盘上时仍然只有 100 MB 左右。但是现在文件大约是 20mb,但我看到我的脚本需要的内存大约是 200/300 mb。显然,脚
Solaris9 x86下如何挂载和永久挂载windows fat32分区 临时挂载Shell 命令; mout –F pcfs /dev/dsk/c1d0p0:c /mnt/c mount
磁盘ID中的资源组名称大小写不敏感。重现此问题的步骤 - 在 Azure 中创建独立磁盘,检查 ID。对于例如 -“/subscriptions/subscriptionID/resourceGrou
我已将附加数据磁盘的备份还原到新虚拟机。当我发出命令 sudo blkid 时,我发现它与附加到原始虚拟机的数据磁盘具有相同的 UUID,因此我无需更改 fstab 即可在启动时挂载它。然而,它似乎是
在用户态中,执行磁盘 IO 就像链接 C 库一样简单,或者,如果您喜欢冒险,可以直接执行系统调用。我想知道内核本身是如何执行 IO 的。 换句话说,假设我在裸机上以特权模式运行应用程序。我将如何访问通
我已将附加数据磁盘的备份还原到新虚拟机。当我发出命令 sudo blkid 时,我发现它与附加到原始虚拟机的数据磁盘具有相同的 UUID,因此我无需更改 fstab 即可在启动时挂载它。然而,它似乎是
我正在尝试使用 laravel 和 ffmpeg 创建缩略图。但是我收到了这个错误。 磁盘 [视频] 没有配置驱动程序。 我的代码 public function index() { FFMp
我的目标是读/写 usb。 首先必须打开并读取 usb 低级别,如“程序” 我使用 visual c++ 和 winAPI 下面是我的测试代码 char path[64]; sprintf(path,
内核缓冲区缓存何时为空?这似乎不是 LINE Buffering。如果我写 () 一个没有换行符的字符串,它会立即输出到文件。 另外,socket文件的输入输出缓冲区是否也像Disk I/O一样使用内
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a software
我有一个大型调用中心,有 250 个并发调用。队列日志的队列应用程序平面文件。该系统使用 Asterisk 和 Queuemetrics。两个服务都在同一台服务器上运行。规范为 16 核和 64 GB
我在使用安装了 Centos7 的 VMWare VM 时遇到问题。 lsblk 命令给出如下内容 df -h 给出这个 我正在尝试将 root lvm 扩展到分区,但无论我如何尝试都无法做到这一点。
在基于内存的计算模型中,通过考虑数据结构,可以抽象地完成唯一需要进行的运行时计算。 但是,关于高性能磁盘 I/O 算法的文档并不多。因此,我提出了以下一组问题: 1) 我们如何估计磁盘 I/O 操作的
我不是在寻找调用命令行实用程序的代码,它可以解决问题。我实际上很想知道用于创建 RAM 磁盘的 API。 编辑 动机:我有一个第三方库,它需要一个目录名,以便以某种方式处理该目录中的文件。我将这些文件
MySQL 数据库显示磁盘 I/O 利用率持续保持在 100% 左右。数据库服务器有 24 GB 内存。 我们尝试优化查询,但效果不佳。 请检查如下所示的当前配置参数: 参数 当前值 key_buff
这是交易。我们本可以采用完全静态 html 的方式来解决性能问题,但由于该站点将是部分动态的,因此这对我们来说行不通。我们想到的是使用 memcache + eAccelerator 来加速 PHP
对于游戏 Minecraft,运行服务器应用程序时的一般方法是在 RAMDisk 中运行它,因为它使用数百个小文件来生成世界,I/O 速度是主要瓶颈。 在最近的尝试中,我尝试使用 Dokan/ImDi
当我查找文件中的某个位置并写入少量数据(20 字节)时,幕后发生了什么? 我的理解 据我所知,可以从磁盘写入或读取的最小数据单位是一个扇区(传统上是 512 字节,但该标准现在正在改变)。这意味着要写
如何使用golang获取xen服务器的内存、磁盘、网络和cpu信息? 是否有任何可用的软件包? 最佳答案 与其他服务器有什么不同?如果没有 - 有一堆 Go 包可以做到这一点,我正在使用这个 - ht
我是一名优秀的程序员,十分优秀!