Upload task using the NSURLSessionUploadTask causing NSURLErrorDomain error -999 - ios

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.

Related

AFNetwork: Getting "finished with error - code: -999" warning

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

what causes XPC error Connection interrupted

I have piece of code that fires couple of requests using NSURLsession and sometimes I get the below message on debugger of xcode
received XPC error Connection interrupted for message type 3
kCFNetworkAgentXPCMessageTypePACQuery
I am thinking what causes this issue ?
Is it something to be worried about ?
Googling doesn't help much
Maybe it is caused by Network Proxy like VPN/VPS ,close them and Command R again.
I got exactly the same error.
During the first attempt I had the VPN on. After turning it off the message did not appear.

iOS/RestKit - request timed out

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];

NSURLSession background upload completion method called twice after restart

I am using NSURLSession in background mode, to upload images from file using a NSURLSessionUploadTask, and the delegate callbacks. All this works perfectly fine if the app remains on the background as opposed to getting killed by the user.
However if while there are still pending uploads, and the app is killed using the home screen, once the app is restarted and the images that did not upload get requeued as upload tasks with a new NSURLSession with the same background identifier, something really odd happens:
1) The tasks are created only once, and I assign a task description to them when that happens, also NSURLSession assigns them a task identifier which is unique per session. My NSURLSession background is a singleton.
2) The tasks fail almost immediately with this error:
Error Domain=NSURLErrorDomain Code=-999 "The operation couldn’t be completed. (NSURLErrorDomain error -999.)" UserInfo=0x174669880 {NSErrorFailingURLStringKey=myURL, NSURLErrorBackgroundTaskCancelledReasonKey=0
and it calls the completion delegate method:
- (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error
passing the aforementioned error above. At this point I print out the task identifier and the task description which matches the task I created.
3) After all this tasks fail almost immediately, that is when things start to get weird, all those tasks get somehow put again into the NSURLSession without my code doing anything, note that using Charles I can see a single request going out, which in reality never fails. This second time they succeed and they call the didCompleteWithError again this time there is no error. At this point printing the task description and task identifier, surprisingly returns the same task description I assigned, BUT a different task identifier!. Meaning iOS is somehow recreating that task with the same task identifier and queuing it up again, even though it claims it failed. Note that the network request can be seen in Charles only once and it never really fails
This is problem because I cannot distinguish between real upload errors, and this pseudo errors generated by iOS, right now since I am not explicitly canceling any of those requests, I am checking the error code for canceled, and choosing to ignore it, since I know the task will just get magically requeued. This seems like a pretty obvious bug to me, and it can be reproduced all the time.
With the workaround in place everything works as expected, but this is a hack, and I can imagine I might at some point ignore a real canceling and never notify the client that the request in fact failed.
I have only found a couple of people online describing the issue, but no responses.
Is there a radar filed for this?. Is there any way to prevent this from happening?
I am using the 8.1 SDK.

Failed to load webpage - error (NSURLErrorDomain error -999)

I have Phonegap project where i have requirement for open iframe, where I am trying to open an iframe with JavaScript. I get the error in iOS
Error: The operation couldn't be completed. (NSURLErrorDomain error -999)
Anyone here knows about this error or how to open iframe in Phonegap iOS.
NSURLErrorCancelled
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. Note that an NSURLConnection or NSURLDownload delegate will not receive this error if the download is canceled.
Available in OS X v10.2 and later.
Declared in NSURLError.h.
NSURLErrorDomain error -999 is triggered when asynchronous network call is cancelled.
NSURLErrorDomain error -999 == NSURLErrorCancelled
Not sure how this would help, but hopefully it'll give you a new perspective.
All the other answers are true, but what to do then?
If you catch the error with the UIWebViewDelegate, you can try reloading the content until it loaded successfully. Just insert the requestWithURL a second time in the
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
delegate. This will cycle until the page loads successfully. This is especially necessary with Facebook and Twitter. If you don't want to run into a deadlock, you can count up an int property in your object that bypasses the request after trying 5 times.

Resources