2012-02-14 10 views
6

Utilizo este método para obtener el espacio libre en el disco, extraído de un código encontrado después de algunas investigaciones.iPhone - Espacio libre en el dispositivo informado incorrectamente (+ - 200 Mb de diferencia)

float freeSpace = -1.0f; 
    NSError* error = nil; 
    NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSDictionary* dictionary = [[NSFileManager defaultManager] attributesOfFileSystemForPath:[paths lastObject] error: &error]; 

    if (dictionary) { 
     NSNumber* fileSystemSizeInBytes = [dictionary objectForKey:NSFileSystemFreeSize]; 
     freeSpace = [fileSystemSizeInBytes floatValue]; 
    } 

Me pregunto por qué, cuando runing esto, me da un espacio libre de 3660062720.000000 bytes que daría 3,408699035644531 Gb (/ 1024/1024/1024)

Pero mirando en mi entorno iPhone - > información general (y también en iTunes), me dicen que a mi iPhone le quedan solo 3.2 Gb.

¿Dónde está el error?

+0

¿Alguna vez ha encontrado una respuesta a esto? –

+1

@PauliusLiekis no – Oliver

Respuesta

2

Parece que a veces el espacio libre se informa incorrectamente https://discussions.apple.com/thread/2566412?threadID=2566412

EDIT: He probado el siguiente código y se dio cuenta de que en mi dispositivo, también hubo una discrepancia 200MB ~. Tal vez ese almacenamiento está reservado para el sistema de alguna manera?

NSDictionary *fsAttr = [[NSFileManager defaultManager] fileSystemAttributesAtPath:NSHomeDirectory()]; 

unsigned long long freeSpace = [[fsAttr objectForKey:NSFileSystemFreeSize] unsignedLongLongValue]; 

NSLog(@"%llu", freeSpace); 
NSLog(@"%f", freeSpace/1073741824.0); 
+1

Interresting. Pero según mi iPhone y no solo iTunes, también es 3.2 Gb ... Y el método devuelve 3.4 ... – Oliver

+0

Actualizado mi respuesta, también noto una diferencia – danielbeard

+0

Muy muy extraño ... – Oliver

Cuestiones relacionadas