Get File from device while debugging

我的未来我决定 提交于 2019-12-13 05:19:46

问题


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.

Please help me Thanks


回答1:


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.

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 */
}


来源:https://stackoverflow.com/questions/8103508/get-file-from-device-while-debugging

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!