可能重复:
How to detect total available/free disk space on the iPhone/iPad device?
我想在iOS应用中获取iOS设备的以下详细信息。我在谷歌搜索过,但我对这些没有任何想法:
答案 0 :(得分:1)
让C系统调用statfs。
请参阅:https://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man2/statfs.2.html
这个SO答案: check enough space on iphone device before downloading files
答案 1 :(得分:1)
总计&可用空间,此方法将返回freeSpace
- (uint64_t)freeDiskspace{
uint64_t totalSpace = 0;
uint64_t totalFreeSpace = 0;
__autoreleasing NSError *error = nil;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSDictionary *dictionary = [[NSFileManager defaultManager] attributesOfFileSystemForPath:[paths lastObject] error: &error];
if (dictionary) {
NSNumber *fileSystemSizeInBytes = [dictionary objectForKey: NSFileSystemSize];
NSNumber *freeFileSystemSizeInBytes = [dictionary objectForKey:NSFileSystemFreeSize];
totalSpace = [fileSystemSizeInBytes unsignedLongLongValue];
totalFreeSpace = [freeFileSystemSizeInBytes unsignedLongLongValue];
NSLog(@"Memory Capacity of %llu MiB with %llu MiB Free memory available.", ((totalSpace/1024ll)/1024ll), ((totalFreeSpace/1024ll)/1024ll));
}
else {
NSLog(@"Error Obtaining System Memory Info: Domain = %@, Code = %d", [error domain], [error code]);
}
return totalFreeSpace;
}
答案 2 :(得分:0)
您可以使用uidevice-extension获取这些内容 您需要的是以下功能:
- (NSNumber *) totalDiskSpace;
- (NSNumber *) freeDiskSpace;
来自UIDevice-Hardware.h
答案 3 :(得分:-1)
您也可以使用NSFileManager和方法
- (NSDictionary *)attributesOfFileSystemForPath:(NSString *)path error:(NSError **)error
在您要发送数据的路径上。此方法使用statfs(在其他答案中提到)。