Hi i am beginner in ios and when ever we are calling services using NSURLRequest i want to know want to know what happening when we are calling services with "Synchronous request" and calling services with asynchronous request programmatically, Please explain that operations programmatically and i have written some code in below using that code explain Synchronous and asynchronous operations
my code:-
- (void)viewDidLoad {
[super viewDidLoad];
NSURL *url = [NSURL URLWithString:@"http://api.kivaws.org/v1/loans/search.json?status=fundraising"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
[theRequest setHTTPMethod:@"GET"];
[theRequest setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[theRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[theRequest setTimeoutInterval:5];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if(connection){
webData = [[NSMutableData alloc] init];
}
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
[webData setLength:0];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[webData appendData:data];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
NSLog(@"error is %@",[error localizedDescription]);
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
NSString * allDataDictionbary = [[NSString alloc] initWithData:webData encoding:NSUTF8StringEncoding];
NSArray * responseString = [allDataDictionbary JSONValue];
NSLog(@"final respone dictionary%@",responseString);
}