将文本文件从 MacBook Pro 传输到 iPad

发布于 2024-10-15 21:52:04 字数 365 浏览 0 评论 0原文

我正在编写一个 iPad 应用程序,它将使用 MacBook Pro 上的多个文本文件作为将在 iPad 上显示的 UITableViews 的数据源。

几个问题:

  1. 我了解,为了让我的应用程序通过 USB/iPad 连接器从 MacBook Pro 获取文件,我的应用程序必须支持文件共享。如何实现此目的?

  2. 自从Apple将iPad变成了一个设备,我就看不到它的文件系统了。那么如何声明存储获取的文件的路径呢? iPad 是具有多个用户主目录的多用户计算机吗?

  3. 我可以编写我的应用程序来与附件连接器中的 SD 卡连接,以便从该卡获取文本文件吗?我应该使用什么类来执行此操作?

I am writing an iPad app that will use several text files on my MacBook Pro as a data source for UITableViews that will display on the iPad.

Several questions:

  1. I understand that in order for my app to fetch files from my MacBook Pro over the USB/iPad connector, my app must support file sharing. How do I accomplish this?

  2. Since Apple made the iPad an appliance, I can't see its file system. So how can I declare paths to store the fetched files? Is the iPad a multi-user computer with multiple user home directories?

  3. Can I write my app to interface with an SD card in the accessory connector so as to fetch text files from that card? What class should I use to do that?

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

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

发布评论

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

评论(1

埖埖迣鎅 2024-10-22 21:52:04
  1. [http://developer.apple.com/library/ios/#documentation/General/Reference/InfoPlistKeyReference/Articles/iPhoneOSKeys.html#//apple_ref/doc/uid/TP40009252-SW1][1]
    将 UIFileSharingEnabled 键添加到您的 Info.plist 文件中。要查看文件,请打开 iTunes,查看左侧面板,单击您的 iPad,查看主内容窗格上方的工具栏,单击“应用程序”,向下滚动,您将看到可以拖放文件和导出文件(但你不能拖动它们,这很烦人)。我实际上也被这个问题难住了。
  2. 让文件共享文件可见的方法是将它们写入一个神奇的目录,该目录是通过以下代码获得的:
    <前><代码>

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString* documentDirPath = [路径 objectAtIndex:0];


    这是我完整使用的例程:
    <前><代码>
    NSString* FileUtils_newUserVisibleFilePath(NSString* toFile) {
    NSAutoreleasePool* 池 = [[NSAutoreleasePool alloc] init];
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString* documentDirPath = [路径 objectAtIndex:0];
    NSString* 文件路径;
    if ([文档目录路径字符AtIndex:[文档目录路径长度]-1] != '/') {
    filePath = [[NSString alloc] initWithFormat:@"%@/%@",documentDirPath,toFile];
    } 别的 {
    filePath = [[NSString alloc] initWithFormat:@"%@%@",documentDirPath,toFile];
    }
    [矿池释放];
    返回文件路径;
    }

  3. 我不知道。但是,我也知道很多 iPad 用户不使用 SD 卡,因此我认为这是少数功能。

一些开发人员最终所做的就是在 iPad 上提供 HTTP 服务器。
[1]: http://developer.apple.com/library/ios/ #documentation/General/Reference /InfoPlistKeyReference/Articles/iPhoneOSKeys.html#//apple_ref/doc/uid/TP40009252-SW1

  1. [http://developer.apple.com/library/ios/#documentation/General/Reference /InfoPlistKeyReference/Articles/iPhoneOSKeys.html#//apple_ref/doc/uid/TP40009252-SW1][1]
    Add the UIFileSharingEnabled key to your Info.plist file. To see the files, open iTunes, look on the left panel, click on your iPad, look at the toolbar above the main content pane, click on "Apps", SCROLL DOWN, and you will see that you can drop files and export files (but you can't drag them, which is annoying). I actually got stumped on this, too
  2. The way you make the file sharing files visible is to write them to a magical directory, which is obtained by the following code:
    
    
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString* documentDirPath = [paths objectAtIndex:0];
    
    

    Here is the routine I use in-full:

    
    NSString* FileUtils_newUserVisibleFilePath(NSString* toFile) {
            NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
            NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
            NSString* documentDirPath = [paths objectAtIndex:0];
            NSString* filePath;
            if ([documentDirPath characterAtIndex:[documentDirPath length]-1] != '/') {
                    filePath = [[NSString alloc] initWithFormat:@"%@/%@",documentDirPath,toFile];
            } else {
                    filePath = [[NSString alloc] initWithFormat:@"%@%@",documentDirPath,toFile];
            }
            [pool release];
            return filePath;
    }
    
    
  3. I have no idea. But, I also know that a lot of iPad users don't use SD cards so I would consider this a minority feature

What some developers end up doing is making an HTTP server available on the iPad.
[1]: http://developer.apple.com/library/ios/#documentation/General/Reference /InfoPlistKeyReference/Articles/iPhoneOSKeys.html#//apple_ref/doc/uid/TP40009252-SW1

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