My iOS app use RestKit framework for implementing RESTful web services client.
Sometimes, I have a problem when I call my server from my application.
The request is not sent and it fails at the end of the expiration with this error:
Error Domain=NSURLErrorDomain Code=-1001 "The request timed out."
At the first openning, it is impossible to reproduce this.
The problem occurs when the application is put into the background and it restarts 10 minutes later or more (it does not produce every time). At this point, there is no server side call .
Then, the only way to solve this problem is to force-quit the application.
We checked there is no error of url, of header, etc ...
HELP ME :'(
Try to set time interval like
[manager.requestSerializer setTimeoutInterval:yourTimeInterval];
Related
I am doing a get API request and everything works fine, but I am getting the following warning in the console.
Task <13369ECB-128E-41B7-B9E4-DC7D3E47D0C1>.<2> finished with error -
code: -999
This only occurs for a certain API endpoint. This makes no sense to me at all. I thought -999 stands for cancelled request, but my requests are finished.
I think this might be a security issue simply because all my get requests work for multiple api endpoints, but not a specific one. Any suggestions are appreciated.
Yes, this means it was canceled, but the question is why
be patient to make sure you didn't cancel the request.
returned when an asynchronous load is canceled. A Web Kit framework delegate will receive this error when it performs a cancel operation on a loading resource.
may be caused by an invalid SSL certificate
I am using the NSURLSessionUploadTask to upload a file to a server. Once the task is resumed, everyone now and then it fails with the error code
NSURLErrorDomain error -999
Now there is no cancel code anywhere in the app. What causes this to get canceled?
I've run into a similar issue before, the answer for me was that another same request was made before the previous request completed. I would check with breakpoints to see if your method that is uploading the file to the server might be hitting twice. Of course it could be another problem, hard to know without seeing any code but I would start there.
So the -999 in my case was a red herring. There were few misleading information on the iOS side :
The -999 error saying it was cancelled, which is user cancellation. This is not true.
The error message had the NSURLErrorBackgroundTaskCancelledReasonKey set to NSURLErrorCancelledReasonUserForceQuitApplication which was again not correct.
The actual problem was the upload file was too big for the server to accept, so the server cancelled the upload. However the translation of the server canceling the event made the error be -999 with the NSURLErrorCancelledReasonUserForceQuitApplication being the reason.
I am using AfNetworking 1.0 into my app.I have created a singleton class of AFHTTP Client.
So all the API's are place in the same class.
I am getting a very wierd issue.
For eg: Let say, i have requested for some data from server.But the internet connection has lost.
So the failure block get's called.
m getting the following error:
Error Domain=NSURLErrorDomain Code=-1009 "The Internet connection appears to be offline." UserInfo=0x797dcc70 {NSErrorFailingURLStringKey=https://testing.com?searchText=s&pageSize=10&pageNumber=5, _kCFStreamErrorCodeKey=57, NSErrorFailingURLKey=https://testing.com?searchText=s&pageSize=10&pageNumber=5, NSLocalizedDescription=The Internet connection appears to be offline., _kCFStreamErrorDomainKey=1, NSUnderlyingError=0x7aa367e0 "The Internet connection appears to be offline."}
But if i try to get the status code using following code:
NSLog(#"Status code %d",[operation.response statusCode]);
m getting Status Code as "0".
Can you please explain,why i am getting Status code as "0"?
I have to handle the error,depends on HTTP Status Code.So what is the best way to get this done?
(the same way which i am doing or is there any other way.)
In this case you can't use the status code because there isn't one. The status code comes from the server and in this case the client has not been able to contact the server.
You should use the error domain and code to handle this case.
I've got NSURLConnection with timeout = 30s which is uploading an image on server.
If connection is horrible and call delegate method didFailWithError: then i need to cancel current connection.
But if i just call the [myConnection cancel] connection will still alive but will not call delegates methods (apple docs say it - NSURLConnection cancel method). And i want to abort connection but not only remove delegate methods. How i can do what?
upd:
My problem is if connection is fails by timeout - in business logic i must recreate connection with similar request. If i have got horrible connection for 1 min and after that connection will be good - server will get a lot of (about 3 times retry count) photos. But first 2 connections is canceled. –
At the moment i make "dirty hack" like "if it's photo uploading request" - do not retry recreate connection.
I do a ton of network stuff and don't recall a scenario where everything was successfully received but the iOS app timed out. I'm trying to grok the scenario you describe, where you're seeing this happen a lot and I'm not seeing how that would happen. We might need to see some of your code.
Regardless, when you cancel a NSURLConnection, it not only stops the delegate methods from being called, but it stops the upload, too. I just did a test:
I attempting to upload a 20mb file (non-chunked request);
At the 1mb mark (as identified by didSendBodyData), I canceled the connection (by calling [connection cancel]);
I immediately stopped receiving any delegate messages at that point;
Looking at Charles, I'm only seeing 1.3mb of data in the hex log of the request. When I look at the "Network" tab of the Mac OS "Activity Monitor" and looking at by "Sent Bytes", it's at 2.1mb uploaded.
So canceling a connection will stop further data from being sent. Perhaps if there is some transmission in progress that still gets out (that's the asynchronous world we live it), but the it's not true to conclude that canceled connections will routinely send their full HTTP request. There must be something about the nature of the timeout that is unique to your environment.
In terms of your immediate problem, I might suggest that when uploading a file that the iOS app assign some unique identifier to the upload so that the server code can immediately recognize duplicate requests and handle them appropriately. But the question is why you are seeing so many time-outs and notably ones where the request appears to be successfully received in toto, but the response is not. That's very curious.
You cannot forcefully abort an ongoing connection.
In case if connection is not yet started cancel and unscheduleFromRunLoop for the NSURLConnection will work.
Try with following step
[myConnection cancel];
myConnection = nil;
Might be helpful in your case and If this step is not working then also try with myConnection.delegate = nil;
I'm using XMPP & OpenFire for my iOS project. The internet connection is stable.
Everything is fine on the first sign in. However from the second time on (sign out then sign in again), it rarely works.
I oftens get readTimeoutError after 10-15s :
Error Domain=GCDAsyncSocketErrorDomain Code=4 "Read operation timed out" UserInfo=0xa8db6a0 {NSLocalizedDescription=Read operation timed out}
Because of that, the app doesn't jump to - (void)xmppStreamDidConnect:(XMPPStream *)sender, thus i'm not connected with OpenFire.
I've spent the whole day on this issue but still can't find the solution. Can anyone help me ?
Found the problems you are facing. Please close your sockets correctly, it will be fine.