2

How can I stop a request(timeout) in AFNetworking if I started a request but no response data for a while such as 30 seconds

LiMo
  • 65
  • 1
  • 8

1 Answers1

1

You need to initialize your NSURLRequest with a timeout value that fits your needs.

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:inURL
 cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:30.0];

Then, initialize AFNetworking's AFHTTPRequestOperation with that initialized NSMutableURLRequest request.

Toseef Khilji
  • 17,192
  • 12
  • 80
  • 121
  • ok,it's helpful.but I don't understand why Matt who's the author of AFNetWorking use the method:NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url]; but not NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:inURL cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:30.0];? – LiMo Oct 10 '13 at 06:03
  • See Matt's answer to [this](http://stackoverflow.com/questions/8304560/how-to-set-a-timeout-with-afnetworking) question. – David Gish Oct 25 '13 at 22:03