Sahitya Tarumani
Sahitya Tarumani

Reputation: 429

NSURLConnection timing out on iOS8

I have been working on an application involving client-server communication. Everything was working fine until iOS 7.1. Now that Xcode 6 GM Seed in launched, I tried to build and run the project on iOS8 simulator. However, all NSURLConnections seem to time out now. I can not get any response from the server. This works on iOS 7 simulator and Xcode 6.
I tried using the NSURLSession hoping that would resolve the issue. But it hasnt.
Any help will be highly appreciated!! If anyone else has faced this issue, please let me know if you have any workaround to this.

UPDATE:
This is the code I have used:

NSString *authStr = [NSString stringWithFormat:@"%@:%@", username, password];  
NSData *authData = [authStr dataUsingEncoding:NSUTF8StringEncoding];  
NSString *authValue = [NSString stringWithFormat: @"Basic %@",[authData base64EncodedStringWithOptions:0]];  
[inURLRequest setValue:authValue forHTTPHeaderField:@"Authorization"];  

Please note that the inURLRequest is already iniatlized with the desired URL.
After this just use the inURLRequest to fire the transaction as usual. For eg., in case of NSURLSession, create a download task using this request object and call resume API on it.

Upvotes: 5

Views: 999

Answers (2)

Sahitya Tarumani
Sahitya Tarumani

Reputation: 429

Well, I have found a fix for this issue.
The app had basic authentication in place for each REST webservice. This means that we used to get an authentication challenge for each webservice where we sent the credentials back with the challenge. I changed this to send the credentials in the request header (in encrypted format) as a header field.

I am not sure how this was working in iOS 7 and not in iOS 8. But this seems to have fixed my problem :).

Upvotes: 1

Iftah
Iftah

Reputation: 9572

If you are streaming data to the NSURLConnection make sure you write new data exactly once when the stream event hasSpaceAvail has arrived - I found I had connection issues when I had wrong handling of the hasSpaceAvail event.

do not write more than once in response to the event

do not write zero times (or else you won't get another hasSpaceAvail event)

Upvotes: 0

Related Questions