Transfering text files from a MacBook Pro to an iPad
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:
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?
Since Apple made the iPad an appliance, I can't see its file system. So how can I declare paths to store the fetc开发者_Python百科hed files? Is the iPad a multi-user computer with multiple user home directories?
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?
- [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
- 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];
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; }
- 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
精彩评论