我创建了一些文件,用于在我的 iPhone 应用程序中存储一些日志信息。它们存储在应用程序的文档文件夹中。我想将它们下载到我的 Mac 上。我可以在 xCode 管理器中看到它们,但无法访问这些文件。我怎样才能做到这一点?
最佳答案
首先,在项目的设置 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
关于ios - 从 PC 上的 iPhone App 的文档文件夹下载创建的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7773399/