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 fetched 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?
\nHere is the routine I use in-full:NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString* documentDirPath = [paths objectAtIndex:0];
\nNSArray *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; }
\nNSString* 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; }
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.