调试时从设备获取文件 [英] Get File from device while debugging

查看:41
本文介绍了调试时从设备获取文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个应用程序,其中我使用设备在plist文件中编写字典.我的Mac中需要该文件.就像我使用模拟器一样,我可以访问我的文档目录,这是可以访问的.当我使用设备和应用程序处于调试模式时,如何在Mac或代码中获取该文件.

I am creating a application in which I am writing dictionary in a plist file using device. I need that file in my Mac. As if I use simulator I can access my document dir coz this is accessible. How can get that file in my mac or my code while I am using device and application is in debug mode.

请帮助我谢谢

推荐答案

Info.plist 文件中启用 UIFileSharingEnabled .然后,将plist复制到 Documents 文件夹中.该文件将在iTunes Apps选项卡的文件共享"部分中进行访问.使用导出"按钮将其复制到Mac上,或将其拖放到文件夹中.

Enable UIFileSharingEnabled in your Info.plist file. Then, copy the plist to Documents folder. The file will be accessible in iTunes Apps tab, File Sharing section. Copy it to your Mac using Export button or just drag and drop to a folder.

要复制文件,您可以从以下代码开始,该代码会将原始plist复制到带有时间戳的新文件,以使分析文件的不同副本更加容易:

To copy the file you can start with this code that will copy the original plist to a new file with a timestamp, to make easier to analyze different copies of the file:

/* ARC */
NSURL plistURL = <# original plist #>
NSString *documents = 
[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd_HH-mm-ss"];
NSString *path = [documents stringByAppendingFormat:@"/TheFile-%@.plist", [dateFormatter stringFromDate:[NSDate date]]];
NSError    *error;
if (![[NSFileManager defaultManager] copyItemAtURL:plistURL 
                                                 toURL:[NSURL fileURLWithPath:path] 
                                                 error:&error]) {
    /* copy failed */
} else {
    /* ok */
}

这篇关于调试时从设备获取文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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