有没有人有例程将 NSFileSystemFreeSize 的结果转换为用户友好的可用 mb/gb 字符串。我以为我掌握了它的要点,但我得到了奇怪的结果。
- (NSString*)getFreeSpace
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSDictionary* fileAttributes = [[NSFileManager defaultManager] attributesOfFileSystemForPath:documentsDirectory error:NULL];
unsigned long long freeSpaceInBytes = [[fileAttributes objectForKey:NSFileSystemFreeSize] unsignedLongLongValue];
NSString * space = [NSString stringWithFormat:@"Free Space: %fll", freeSpaceInBytes /1024. / 1024. /1024.];
NSLog(@"freeSpaceInBytes %llull %fll", freeSpaceInBytes, freeSpaceInBytes /1024. / 1024. /1024.);
return space;
}