从iPhone登录:文件在哪里? [英] Logging from the IPhone: where is the file?

查看:49
本文介绍了从iPhone登录:文件在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过此代码从iPhone应用程序在MacOS FS上创建文件

I am trying to creating a file on my MacOS FS from my IPhone app by means of this code

 [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执行时,我实际上看不到文件的创建位置.如果我打印路径,我将得到

I guess the code is OK as it works when executed by the Simulator. However I can't actually see where the file is created when executed from the IPhone. If I print the path I get

/var/mobile/Applications/XXX-XXXX-XXX-XXX/Documents/log.txt

/var/mobile/Applications/XXX-XXXX-XXX-XXX/Documents/log.txt

推荐答案

在模拟器上,您应该在以下位置找到它们:/Users/loginname/Library/Application Support/iPhone Simulator/5.1/Applications/594931F3-B9EF-4B2C-833D-76C2DCC61C6B/文档.您可以通过以下方法从Finder转到该位置:选择转到"菜单项,按住Option键,然后选择库".

On the simulator, you should find them under: /Users/loginname/Library/Application Support/iPhone Simulator/5.1/Applications/594931F3-B9EF-4B2C-833D-76C2DCC61C6B/Documents. You can go to this location from Finder by choosing the Go menu item, holding down the Option key, then choosing Library.

注意:在上面的路径中填写您自己的登录名和设备ID.

NOTE: Fill in your own loginname and device ID in the path above.

如果您在设备上,则可以使用管理器(选择窗口" |管理器")使用XCode将文件复制到Mac.突出显示该应用程序(当然,在执行后),并且有一个复制文件的选项.您无权直接访问设备文件系统.

If you are on the device, you can copy the file over to your Mac using XCode, using the organizer (choose Window | Organizer). Highlight the App (after it has been executed, of course) and there is an option to copy the file over. You don't have direct access to the device file system.

您还可以使用NSLog(),它仅将调试信息发送到XCode的输出窗口.

You can also use NSLog() which just sends the debug info to the output window in XCode.

添加了有关如何显示库文件夹的详细信息.

Added detail on how to show Library folder.

这篇关于从iPhone登录:文件在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆