NSURLConnection timeout on iOS8

I am working on an application using client-server communication. Everything worked fine until iOS 7.1. Now that the Xcode 6 GM Seed is running, I tried to create and run a project on the iOS8 simulator. However, all NSURLConnections do not seem to be working right now. I can not get a response from the server. This works on the iOS 7 and Xcode 6 simulator.
I tried using NSURLSession, hoping this solves the problem. But it does not have. Any help would be greatly appreciated! If anyone else has encountered this problem, let me know if you have a workaround.

UPDATE :
This is the code I 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 inURLRequest is already italized with the desired URL.
After that, just use inURLRequest to start the transaction, as usual. For example, in the case of NSURLSession, create a download task using this request object and call the resume API on it.

+5
source share
2 answers

Well, I found a fix for this problem.
The application had basic authentication for each REST web service. This means that we used authentication for every web service where we sent the credentials back with a call. I changed this to send credentials to the request header (in encrypted format) as the header field.

I'm not sure how this works in iOS 7 and not in iOS 8. But this seems to fix my problem :).

+1
source

If you are transferring data to NSURLConnection, make sure to write new data exactly once when the hasSpaceAvail stream event arrived — I found that I had connectivity problems when I had the wrong handling of the hasSpaceAvail event.

write no more than once in response to an event

do not write zero time (otherwise you will not get another hasSpaceAvail event)

0
source

Source: https://habr.com/ru/post/1202416/


All Articles