-(void)usedSpaceAndfreeSpace{
NSString* path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] ;
NSFileManager* fileManager = [[NSFileManager alloc ]init];
NSDictionary *fileSysAttributes = [fileManager attributesOfFileSystemForPath:path error:nil];
NSNumber *freeSpace = [fileSysAttributes objectForKey:NSFileSystemFreeSize];
NSNumber *totalSpace = [fileSysAttributes objectForKey:NSFileSystemSize];
spaceLabel.text = [NSString stringWithFormat:@"已占用%0.1fG/剩余%0.1fG",([totalSpace longLongValue] - [freeSpace longLongValue])/1024.0/1024.0/1024.0,[freeSpace longLongValue]/1024.0/1024.0/1024.0];
}
-(void)usedSpaceAndfreeSpace{
NSString* path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] ;
NSFileManager* fileManager = [[NSFileManager alloc ]init];
NSDictionary *fileSysAttributes = [fileManager attributesOfFileSystemForPath:path error:nil];
NSNumber *freeSpace = [fileSysAttributes objectForKey:NSFileSystemFreeSize];
NSNumber *totalSpace = [fileSysAttributes objectForKey:NSFileSystemSize];
spaceLabel.text = [NSString stringWithFormat:@"已占用%0.1fG/剩余%0.1fG",([totalSpace longLongValue] - [freeSpace longLongValue])/1024.0/1024.0/1024.0,[freeSpace longLongValue]/1024.0/1024.0/1024.0];
}
iOS应用存储空间查询
本文介绍了一种在iOS应用中获取设备已用和剩余存储空间的方法。通过使用NSFileManager和相关属性,可以准确地获取到应用程序目录的文件系统大小及可用空间大小,并将其转换为易于理解的GB单位。

768

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



