I am a noob in NSURLConnection
. I have searched Google and found this site but I dont understand about it.
My friends please explain the code that I have downloaded from url in Document folder.
This is my code :
- (void)viewDidLoad
{
[super viewDidLoad];
NSURL *url =[NSURL URLWithString:@"http://cdn.arstechnica.net/wp-content/uploads/2012/09/iphone5-intro.jpg"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
NSURLConnection *con = [[NSURLConnection alloc]initWithRequest:request delegate:self];
[con start];}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
//I dont know what thing put here
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)theData
{
//I dont know what thing put here
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
//I dont know what thing put here
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
UIAlertView *errorView = [[UIAlertView alloc]initWithTitle:@"Error" message:@"The Connection has been LOST" delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
[errorView show];
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}
It would be good to do it asynchronously with NSURLConnection with blocks.
Using NSURLConnection ,Try this
For more info on NSURLConnection Refer this :URL Loading System Programming Guide
EDIT
Here
recievedData
is the instance variable of typeNSMutableData
Without using
NSURLConnection
you can easily download files, then no need to overhead delegate calls. Simply try this.