问题
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