NSString *path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask , YES)objectAtIndex:0];
NSFileManager *fileManager = [NSFileManagerdefaultManager];
NSDictionary *fileSysAttributes = [fileManagerattributesOfFileSystemForPath:path error:nil];
NSNumber *freeSpace = [fileSysAttributesobjectForKey:NSFileSystemFreeSize];
NSNumber *totalSpace = [fileSysAttributesobjectForKey:NSFileSystemSize];
NSString *total = [NSStringstringWithFormat:@"总空间为:%0.1fG",([totalSpacedoubleValue])/1024.0/1024.0/1024.0];
NSString *free = [NSStringstringWithFormat:@"剩余:%0.1fG",([freeSpacedoubleValue])/1024.0/1024.0/1024.0];
NSString *use = [NSStringstringWithFormat:@"已用:%0.1fG",([totalSpacedoubleValue]-[freeSpace doubleValue])/1024.0/1024.0/1024.0];
NSLog(@"total : %@, free : %@, use : %@",total,free,use);
本文介绍了一种使用Objective-C在iOS设备上获取存储空间信息的方法,包括总空间、已用空间及剩余空间,并通过示例代码展示了如何利用NSFileManager和NSSearchPathForDirectoriesInDomains来获取这些信息。
1040

被折叠的 条评论
为什么被折叠?



