ubicacion tengo sistema rutas otros ocupa nada mucho mapas lleno limpiar hay funciona esta espacio documentos disponibles desde datos cómo como borrar apartado almacenamiento iphone ios filepath

iphone - tengo - no hay rutas disponibles desde esta ubicacion



¿Qué indica el prefijo/private en una ruta de archivo de iOS? (5)

  1. En mi caso, mientras uso FileManager.default.fileExists para verificar si el archivo ya existe pero estaba usando .absoluteString / "()" . en lugar de .path para pasar la URL como String.
  2. Cuando imprimí las rutas de los archivos en el Directorio de Documentos usando

deje fileURLs = pruebe fileManager.contentsOfDirectory (en:

se imprime como /private/var

Deje que DocumentDirURL = intente! FileManager.default.url (para: .documentDirectory, en: .userDomainMask, apropiado For: nil, create: true)

se imprimió como /var

  1. Esta diferencia en el camino me confundió.
  2. Como explicamos anteriormente es solo un enlace simbólico . Es decir, ambos caminos son iguales.

:)

Tengo un error cuando mi aplicación se ejecuta en el iPhone, pero no cuando se ejecuta en el simulador. Estaba utilizando la longitud de la ruta del directorio principal para extraer la ruta relativa de un archivo en / Documentos. Desafortunadamente, esto no siempre funciona correctamente en el iPhone porque el prefijo "/ private" se está agregando a la ruta de inicio. Sin embargo, con o sin el prefijo, se hace referencia al mismo archivo ok. El siguiente código demuestra esta inconsistencia. ¿Cuál es el propósito de "/ private" y cuándo lo suministra iOS?

- (IBAction)testHomepath:(id)sender { NSFileManager *fmgr = [NSFileManager defaultManager]; NSString *homePath = [NSString stringWithFormat:@"%@/Documents",NSHomeDirectory()]; NSString *dirPath = [homePath stringByAppendingPathComponent:@"TempDir"]; NSURL *dirURL = [NSURL fileURLWithPath:dirPath]; NSString *filePath = [dirPath stringByAppendingPathComponent:@"test.jpg"]; [fmgr createDirectoryAtPath:dirPath withIntermediateDirectories:NO attributes:nil error:nil]; [fmgr createFileAtPath:filePath contents:nil attributes:nil]; NSArray *keys = [[NSArray alloc] initWithObjects:NSURLNameKey,nil]; NSArray *files = [fmgr contentsOfDirectoryAtURL:dirURL includingPropertiesForKeys:keys options:0 error:nil]; NSURL *f1 = (files.count>0)? [files objectAtIndex:0] : 0; NSURL *f2 = (files.count>1)? [files objectAtIndex:1] : 0; bool b0 = [fmgr fileExistsAtPath:filePath]; bool b1 = [fmgr fileExistsAtPath:f1.path]; bool b2 = [fmgr fileExistsAtPath:f2.path]; NSLog(@"File exists=%d at path:%@",b0,filePath); NSLog(@"File exists=%d at path:%@",b1,f1.path); NSLog(@"File exists=%d at path:%@",b2,f2.path); }

Lo siguiente está escrito en el registro cuando se ejecuta en el iPhone. Separé manualmente la salida para mostrar la diferencia entre las líneas 1 y 2.

2013-02-20 16:31:26.615 Test1[4059:907] File exists=1 at path: /var/mobile/Applications/558B5D82-ACEB-457D-8A70-E6E00DB3A484/Documents/TempDir/test.jpg 2013-02-20 16:31:26.622 Test1[4059:907] File exists=1 at path:/private/var/mobile/Applications/558B5D82-ACEB-457D-8A70-E6E00DB3A484/Documents/TempDir/test.jpg 2013-02-20 16:31:26.628 Test1[4059:907] File exists=0 at path:(null)

Lo siguiente se escribe en el registro cuando se ejecuta en el simulador (no "/ private"):

2013-02-20 16:50:38.730 Test1[7224:c07] File exists=1 at path:/Users/kenm/Library/Application Support/iPhone Simulator/6.1/Applications/C6FDE177-958C-4BF5-8770-A4D3FBD281F1/Documents/TempDir/test.jpg 2013-02-20 16:50:38.732 Test1[7224:c07] File exists=1 at path:/Users/kenm/Library/Application Support/iPhone Simulator/6.1/Applications/C6FDE177-958C-4BF5-8770-A4D3FBD281F1/Documents/TempDir/.DS_Store 2013-02-20 16:50:38.733 Test1[7224:c07] File exists=1 at path:/Users/kenm/Library/Application Support/iPhone Simulator/6.1/Applications/C6FDE177-958C-4BF5-8770-A4D3FBD281F1/Documents/TempDir/test.jpg


En Swift 3, la URL tiene la propiedad standardizedFileUrl , que eliminará cualquier URL simbólico y resolverá las partes relativas dentro de la ruta como ./ .

Al momento de escribir, la documentation es bastante inútil, pero parece que es equivalente a la propiedad standardized NSURL .


Intenté esto desde el depurador y descubrí que URLByResolvingSymlinksInPath "corrige" el /private/ URLByResolvingSymlinksInPath .

(lldb) p (NSURL *)[NSURL fileURLWithPath:@"/private/var" isDirectory:YES] (NSURL *) $1 = 0x1fd9fc20 @"file://localhost/private/var/" (lldb) po [$1 URLByResolvingSymlinksInPath] $2 = 0x1fda0190 file://localhost/var/ (lldb) p (NSURL *)[NSURL fileURLWithPath:@"/var" isDirectory:YES] (NSURL *) $7 = 0x1fd9fee0 @"file://localhost/var/" (lldb) po [$7 URLByResolvingSymlinksInPath] $8 = 0x1fda2f50 file://localhost/var/

Como puede ver, el file://localhost/var es lo que realmente queremos aquí.

Debido a esto, parecía obvio que /private/var es un enlace simbólico a /var . Sin embargo, @ Kevin-Ballard señala que eso no es cierto. Confirmé que él es correcto, y /var es el enlace simbólico a /private/var (suspiro)

(lldb) p (NSDictionary *)[[NSFileManager defaultManager] attributesOfItemAtPath:@"/var" error:nil] (NSDictionary *) $3 = 0x1fda11b0 13 key/value pairs (lldb) po $3 $3 = 0x1fda11b0 { ... NSFileType = NSFileTypeSymbolicLink; } (lldb) p (NSDictionary *)[[NSFileManager defaultManager] attributesOfItemAtPath:@"/private/var" error:nil] (NSDictionary *) $5 = 0x1fda4820 14 key/value pairs (lldb) po $5 $5 = 0x1fda4820 { ... NSFileType = NSFileTypeDirectory; }

Así que URLByResolvingSymlinksInPath está haciendo algo gracioso aquí, pero ahora lo sabemos. Para este problema en particular, URLByResolvingSymlinksInPath todavía suena como una buena solución que funciona tanto para el simulador como para el dispositivo y debería continuar funcionando en el futuro si algo cambia.


Para responder realmente a su pregunta:

Creo que /private fue un prefijo agregado cuando lanzaron OS X (no creo que estuviera allí en NeXTStep, pero sí décadas ). Parece existir en house, etc , var , y tmp (y, curiosamente, tftpboot ; no sabía que mi PBG4 podría hacer eso), tal vez los usuarios no se preguntan qué es esta carpeta tan tonta llamada etc y tratan de eliminarla. .

En el dispositivo, Apple decidió almacenar los datos del usuario en /private/var/mobile (el nombre de usuario es "mobile"). No estoy seguro de por qué no eligieron /Users/mobile o simplemente /mobile , pero no tiene más importancia que la que tiene /var/mobile en un Unix "normal".

En el simulador, su cuenta de usuario no puede escribir en /var (por una buena razón). Los datos del usuario se almacenan en algún lugar en ~/Library/Application Support/iPhone Simulator . En un momento dado, comenzaron a usar diferentes directorios para diferentes versiones de simuladores.


/var es solo un enlace simbólico a /private/var . Así que la primera ruta es la ruta lógica a la que intentaste acceder. El segundo es ese mismo camino con enlaces simbólicos expandidos.