NSMutableURLRequest not obeying my timeoutInterval

There’s a thread on Apple dev forums discussing this issue. Apparently on iPhone OS, the setter mandates timeoutInterval a minimum of 240 seconds (4 minutes). This only occurs when the postBody is not empty (typically when using a POST request). This seems crazy, but apparently it’s there to make sure requests leave the system even … Read more

How can I get NSURLResponse body?

Why do you cancel the connection? After all, 404 can have content body as well. Just don’t cancel it, and let the program call the next delegate NSURLConnection method. When the data [the content body] is sent – (void)connection:(NSURLConnection *) didReceiveData:(NSData *) is called, you need to retrieve the data there. Read corresponding part in … Read more

Reading data from response header of NSURLConnection

If the URL is an HTTP URL, then the NSURLResponse that you receive in your connection’s delegate’s -connection:didReceiveResponse: method (or via another method) will be an NSHTTPURLResponse, which has an -allHeaderFields method that lets you access the headers. NSURLResponse* response = // the response, from somewhere NSDictionary* headers = [(NSHTTPURLResponse *)response allHeaderFields]; // now query … Read more

NSURLConnection and grand central dispatch

I recommend you to see WWDC Sessions about network application in iPhone OS. WWDC 2010 Session 207 – Network Apps for iPhone OS, Part 1 WWDC 2010 Session 208 – Network Apps for iPhone OS, Part 2 The lecturer said “Threads Are Evilâ„¢” for network programming and recommended to use asynchronous network programming with RunLoop. … Read more

How to use iOS Reachability

Reachability is a network helper utility class, its used to get various informations about the connection status What is the main purposes of Reachability? Reachability is used to query the network status, and to register your listeners to get informed when connectivity changes. Is this the main purpose of Reachability, to show the user a … Read more

SSL Error in Connection to Server through iPhone

iOS 9 forces connections that are using HTTPS to be TLS 1.2 to avoid recent vulnerabilities. In iOS 8 even unencrypted HTTP connections were supported, so that older versions of TLS didn’t make any problems either. As a workaround, you can add this code snippet to your Info.plist: <key>NSAppTransportSecurity</key> <dict> <key>NSAllowsArbitraryLoads</key> <true/> </dict> Thereby you’re … Read more

Asynchronous request to the server from background thread

Yes, the thread is exiting. You can see this by adding: -(void)threadDone:(NSNotification*)arg { NSLog(@”Thread exiting”); } [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(threadDone:) name:NSThreadWillExitNotification object:nil]; You can keep the thread from exiting with: -(void) downloadImage { NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; [self downloadImage:urlString]; CFRunLoopRun(); // Avoid thread exiting [pool release]; } However, this means the thread … Read more