我创建了一些在我的iPhone App中存储一些日志信息的文件。它们存储在App的文档文件夹中。我想将它们下载到我的Mac上。我能够在xCode管理器中看到它们,但我无法访问这些文件。我怎样才能做到这一点?
答案 0 :(得分:4)
首先,在项目的设置plist上设置Application supports iTunes file sharing
。它也可以命名为UIFileSharingEnabled
。
然后,对于代码,将文件保存在NSDocumentDirectory
中,如下所示:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Id its a local file in the app use its name. If not, alter for your needs.
NSString *fileName = @"someFile.png";
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *documentDBFolderPath = [documentsDirectory stringByAppendingPathComponent:fileName];
if (![fileManager fileExistsAtPath:documentDBFolderPath]) {
NSString *resourceDBFolderPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:fileName];
[fileManager copyItemAtPath:resourceDBFolderPath toPath:documentDBFolderPath error:&error];
}
[self.window makeKeyAndVisible];
return YES;
}
全部来自iOS Dev Tips - File Sharing from App to iTunes is too easy
答案 1 :(得分:4)
使用管理器中的“下载”按钮,您可以将.xcappdata
包保存到Mac(Xcode 4.2,以前的版本只保存文件夹)。您可以右键单击并选择“显示包内容”,将打开Finder窗口,您可以在其中找到Documents文档目录的副本。