I am using NSURLSessionDataTask
and NSMutableURLRequest
. I noticed that the NSMutableURLRequest
has a timeout (240 seconds I believe, which is a long time). I also read that NSURLSession
has a timeout also but I am unsure of exactly what it is. My question is, will the app crash if I do not handle a timeout if it occurs? Is it necessary to handle timeouts or does the OS handle it and prevents the app from crashing, and just kills the request. If we must handle it then it would be great to get some feedback in regards to my code example;
NSURLSession * session = [NSURLSession sharedSession];
NSURL * url = [[NSURL alloc] initWithString:self.url];
NSMutableURLRequest * request = [[NSMutableURLRequest alloc] initWithURL:url];
[request setHTTPMethod:@"POST"];
[request addValue:@"application/x-www-form-urlencoded; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
NSString * params =[NSString stringWithFormat:@"email=%@",some email];
[request setHTTPBody:[params dataUsingEncoding:NSUTF8StringEncoding]];
NSURLSessionDataTask * task = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
NSHTTPURLResponse * httpResp = (NSHTTPURLResponse *)response;
NSDictionary * dataDictionary = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
//some code missing
}
[task resume];