从 PC 上的 iPhone 应用程序的文档文件夹中下载创建的文件

发布于 2024-12-09 16:21:34 字数 117 浏览 6 评论 0原文

我创建了一些文件,在我的 iPhone 应用程序中存储一些日志信息。它们存储在应用程序的文档文件夹中。我想将它们下载到我的 Mac 上。我可以在 xCode 管理器中看到它们,但无法访问这些文件。我怎样才能实现这个目标?

I created some files which store some logging information in my iPhone App. They are stored in the App's document folder. I would like to download them onto my Mac. I'm able to see them in the xCode organizer but I'm not able to access these files. How can I achieve this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

别念他 2024-12-16 16:21:34

首先,在项目的设置 plist 上设置应用程序支持 iTunes 文件共享。它也可以命名为 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 开发技巧 - 从 App 到 iTunes 的文件共享太简单了

First, set Application supports iTunes file sharing on on your project's settings plist. It could also be named UIFileSharingEnabled.
enter image description here

Then, for the code, save the file in NSDocumentDirectory like so:

- (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;
}

All taken from iOS Dev Tips - File Sharing from App to iTunes is too easy

梦归所梦 2024-12-16 16:21:34

Organizer

使用管理器中的“下载”按钮可将 .xcappdata 包保存到您的 Mac (Xcode 4.2,以前的版本只保存一个文件夹)。您可以右键单击并选择“显示包内容”,将打开一个 Finder 窗口,您可以在其中找到 Documents 目录的副本。

Organizer

Using the Download button in the Organizer allows you to save a .xcappdata package to your Mac (Xcode 4.2, previous versions just save a folder). You can right-click and choose "Show Package Contents", a Finder window will open and you can find a copy of the Documents directory therein.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文