Hi I want to ask for a good tutorial that shows me how to download a file from URL to local phone storage using objective C I have done the following its sync but i want to make it a synch
NSString* docsDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSString* fileToDownload = @"data1.plist";
NSString* hostURLString = @"http://localhost/test";
hostURLString = [hostURLString stringByAppendingPathComponent: fileToDownload];
NSURL* pListURL = [NSURL URLWithString: hostURLString];
NSData* pListData = [NSData dataWithContentsOfURL: pListURL];
NSString* filePath = [docsDir stringByAppendingPathComponent: fileToDownload];
[pListData writeToFile: filePath atomically: NO];
NSString* Path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSString *DataPath = [Path stringByAppendingPathComponent:@"data1.plist"];
Any suggestions
Below is my code for async downloading images and data. You can play with it for your aims.
The Using NSURLConnection section of the URL Loading System Programming Guide explains how to create an asynchronous connection, and also how to download synchronously.
Another option is to use ASIHTTPRequest, which can also do either synchronous or asynch requests.