0

I am dealing with a strange network issue. On iOS 7 a server call is randomly reaching twice on sever. This does not happen with iOS 6.

From server logs it appears that same request (I am sending a unique ID in each server request) is coming twice but from client we are sending only 1 request.

Is this a known issue with iOS 7? Or am I missing something on client? Or could it be something on server?

Please suggest.

Below is my code for making a server call:

self.URLRequest = [NSMutableURLRequest requestWithURL:self.URL cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:999];
[self.URLRequest setHTTPMethod:[self methodStringForMethod:self.requestMethod]];
[self.URLRequest setValue:[self.requestHeader valueForKey:aHeaderKey] forHTTPHeaderField:aHeaderKey];
[self.URLRequest setValue:@"gzip" forHTTPHeaderField:@"Accept-Encoding"];
[self.URLRequest setHTTPBody:[self keyValuePostDataFromDictionary:self.body]];

if (self.connection) {
    [self.connection cancel];
    self.connection = nil;
}

self.connection = [[NSURLConnection alloc] initWithRequest:self.URLRequest delegate:self];
self.inFlight = YES;

// if we aren't on the main thread, spool the run loop to pretend to be busy until the request comes back
if ([NSThread currentThread] != [NSThread mainThread]) {
   do {
        [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
      } while (self.inFlight);
}
Abhinav
  • 37,684
  • 43
  • 191
  • 309
  • I think it's unlikely that iOS 7's `NSURLConnection` will fire off duplicate requests. Forcing the runloop like you're doing is certainly goofy, and could be getting you into trouble depending on what your delegate code looks like. Why not use `+sendSynchronousRequest:returningResponse:error:` on NSURLConnection? – Ben Zotto Feb 05 '14 at 23:20
  • I do not want to stuck the main thread with synchronous calls and have my UI blocked because of that. What do you think could go wrong in NSDefaultRunLoopMode? – Abhinav Feb 05 '14 at 23:30

0 Answers0