wurde ein falscher Wert festgestellt. Ich folge http://kdbdallas.com/2008/12/27/maciphone-show-availble-useable-diskspace/ und how do i find out iphone Disk Space? , um den verfügbaren Speicherplatz zu ermitteln. Allerdings scheint, dass das Ergebnis nicht korrekt istBeim Erfassen des verfügbaren Speicherplatzes auf dem iphone
Ich habe auf iPhone 4 ios 4.2.1 getestet.
in Rahmen, Kapazität beträgt 29,1 G Verfügbarkeit beträgt 24,2 G
Ich möchte 24.2 G-Wert erhalten. Also folgte ich dem oben erwähnten Tutorial.
int main(int argc, char *argv[]) {
.....
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSLog(@"path %@", paths);
struct statfs tStats;
statfs([[paths lastObject] UTF8String], &tStats);
NSString *sizeType;
float total_space = (float)(tStats.f_blocks * tStats.f_bsize);
NSLog(@"total space: %f", total_space);
NSLog(@"total space: %@", convertUnit(total_space));
float free_space = (float)(tStats.f_bfree * tStats.f_bsize);
NSLog(@"free space: %f", free_space);
NSLog(@"free space: %@", convertUnit(free_space));
float free_space2 = (float)(tStats.f_bavail * tStats.f_bsize);
NSLog(@"free blocks avail to non-superuser: %f", free_space2);
NSLog(@"free blocks avail to non-superuser: %@", convertUnit(free_space2));
uint32_t block_size = (tStats.f_bsize);
NSLog(@"block size: %d", block_size);
NSLog(@"block size: %@", convertUnit(block_size));
.....
}
NSString* convertUnit (float value) {
NSString *sizeType;
if (value > 1024)
{
//Kilobytes
value = value/1024;
sizeType = @" KB";
}
if (value > 1024)
{
//Megabytes
value = value/1024;
sizeType = @" MB";
}
if (value > 1024)
{
//Gigabytes
value = value/1024;
sizeType = @" GB";
}
return [[@"Available Disk Space: " stringByAppendingFormat:@"%.2f", value] stringByAppendingString:sizeType];
}
ERGEBNIS:
total space: 17363854862722269184.000000
total space: Available Disk Space: 16171350016.00 GB
free space: 17743592094095638528.000000
free space: Available Disk Space: 16525007872.00 GB
free blocks avail to non-superuser: 17432956969504735232.00000
free blocks avail to non-superuser: Available Disk Space: 16235706368.00 GB
block size: 803203484
block size: Available Disk Space: 765.99 MB