IOS Simulator believes the document directory is / var / root / Documents

I try to read all the files in the simulator in the Documents directory, but I get a Cocoa 260 error message. When I log into the [self applicationDocumentsDirectory] log, it says / var / root / Documents. Does anyone know why this will happen? This only happens when starting from the command line. When launched in the simulator itself, the code correctly displays the right document folder for the simulator.

UPDATE Now I see the file path: // localhost / Users / MyUserName / Documents. So strange...

 - (NSString *)applicationDocumentsDirectory { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil; return basePath; } 
+4
source share
1 answer

The fix was for chmod -R 777 "/ Users / MyUserName / Documents", and then change my method to this:

 - (NSString *)applicationDocumentsDirectory { NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil; if (![[NSFileManager defaultManager] createDirectoryAtPath:basePath withIntermediateDirectories:YES attributes:nil error:NULL]) { NSLog(@"Error: Create documents folder failed %@", basePath); } return basePath; } 
+3
source

All Articles