我正在尝试通过此代码从我的 iPhone 应用程序在我的 MacOS FS 上创建一个文件
[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) ];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *path = [paths objectAtIndex:0];
path = [path stringByAppendingPathComponent: @"log.txt"];
NSFileHandle *output = [NSFileHandle fileHandleForWritingAtPath:path];
if(output == nil) {
[[NSFileManager defaultManager] createFileAtPath:path contents:nil attributes:nil];
output = [NSFileHandle fileHandleForWritingAtPath:path];
} else {
[output seekToEndOfFile];
}
我猜代码没问题,因为它在模拟器执行时可以工作。但是,当从 iPhone 执行时,我实际上看不到文件的创建位置。如果我打印我得到的路径
/var/mobile/Applications/XXX-XXXX-XXX-XXX/Documents/log.txt