Documents folder and UIFileSharing
Mar 15
Programming Cocoa touch, Documents folder, iPad, iPhone, iPod touch, SDK, UIFileSharing No Comments
On the iOS, we can only save files on the documents folder. The bundle for example, is not writable. Getting the path of the documents folder is easy. Just use the following code:
NSArray *array = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documents = [[array objectAtIndex:0] copy];
The variable documents will be the path to the documents folder. Now if you want to create an URL from it, use the following code:
NSURL *url = [NSURL URLWithString:documents];
Say you saved a couple files and want your users to be able to transfer it to their computers. On iOS 3.2, Apple introduced UIFileSharing. It allows users to transfer files from their iOS devices to any computer running iTunes. To enable that, just add the Application supports iTunes file sharing line to your info.plist and check the box.
Your users will be able to transfer any file from the documents folder to a computer. To do that, open iTunes then click on your device name. Go to the apps tab and scroll down.
Just drag and drop any file to/from the documents table view.
Twitter
Facebook