J'ai des problèmes pour créer des répertoires et des fichiers avec NSFileManager sur le périphérique iPhone. Mon code, montré ci-dessous, fonctionne bien sur le simulateur, mais pas sur l'appareil, pourriez-vous s'il vous plaît m'aider? Donne-moi des directions où le problème peut être, merci pour chaque réponse ..NSFileManager fonctionne correctement sur le simulateur mais pas sur le périphérique
Je suis d'abord la création de répertoires de cette façon:
NSFileManager *fileMgr = [NSFileManager defaultManager];
NSArray *arPaths = NSSearchPathForDirectoriesInDomains(NSDownloadsDirectory, NSUserDomainMask, YES);
NSString *appPath = [[NSString alloc] init];
appPath = [arPaths objectAtIndex:0];
strDownloadsDir = [[NSString alloc] init];
strDownloadsDir = [[appPath stringByAppendingPathComponent:@"/Other"] copy];
if(![fileMgr fileExistsAtPath:strDownloadsDir])
[fileMgr createDirectoryAtPath:strDownloadsDir attributes:nil];
et je suis en train de créer un nouveau fichier dans ce répertoire ainsi :
NSString *filePath = [strDownloadsDir stringByAppendingPathComponent:strDlFileName];
//Test whether this file exists, if not, create it
NSLog(@"%@", filePath);
if(![fileMgr fileExistsAtPath:filePath])
{
if([fileMgr createFileAtPath:filePath contents:nil attributes:nil])
NSLog(@"Creating new file at path %@", filePath);
else
NSLog(@"Failed to create new file.");
}
Il semble qu'il y ait quelque chose de mal avec tout NSFileManager, parce que quand j'utilise fileExistAtPath avec un chemin donné par ce
NSArray *arPaths = NSSearchPathForDirectoriesInDomains(NSDownloadsDirectory, NSUserDomainMask, YES);
NSString *appPath = [[NSString alloc] init];
appPath = [arPaths objectAtIndex:0];
il ne fonctionne pas trop, j'ai essayé de changer de répertoire à NSDocumentsDirectory mais il n'a pas aidé
Vous avez beaucoup de NSStrings. Ne faites pas inutile [[NSString alloc] init]; '. – kennytm