Error code NSURLErrorDomain -999 in iOS

I am trying to use the Facebook Corona SDK API to post a rating of a game that I am developing on facebook. However, I have a problem with this. The first time I try to post to facebook, I get this error after authenticating user and user:

NSURLErrorDomain Error Code -999

Then he will not post to facebook. What are the possible causes of this error and how can I fix it? I tried searching the Internet but could not find information about it. Thanks in advance.

By the way, I do not use webview in my application. Just an api widget and show_dialog listener in my facebook class.

+64
ios lua nsurl nsurlerrordomain corona
Apr 18 '13 at 2:27
source share
9 answers

The error was documented in the Mac Developer Library (documents for iOS)

The relevant segment from the documentation will be:

System URL Download Codes

These values โ€‹โ€‹are returned as a property of the error code of the NSError object with the domain "NSURLErrorDomain".

enum { NSURLErrorUnknown = -1, NSURLErrorCancelled = -999, NSURLErrorBadURL = -1000, NSURLErrorTimedOut = -1001, 

As you can see; -999 caused by ErrorCancelled . This means: another request is made before the previous one is completed.

+126
Apr 18 '13 at 6:38
source share

hjpotter92 is absolutely right, I just want to provide a solution for my business. I hope this is useful to you. Here is my situation:

On the login page> click in the log> popup download dialog> call log in the service> cancel the dialog> click another screen> call another service โ†’ cause error -999

To fix this, I set a delay between rejecting the dialog and clicking on a new screen:

  [indicatorAlert dismissWithClickedButtonIndex:0 animated:YES]; dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.01 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{ [self performSegueWithIdentifier:@"HomeSegue" sender:nil]; }); 

It is strange that this problem only occurs on iOS 7.

+11
Nov 29 '13 at 7:31
source share

I just wanted to add here that when getting -999 "cancelled" problem usually consists in one of two things:

  • You are doing the same request again.
  • You maintain a weak reference to your manager object which is prematurely freed. (Create a strong link)
+7
Jan 14 '19 at 9:34 am
source share

I did not use the Corona SDK Facebook API, but I ran into this problem when using Alamofire, secondRequest always canceled execution with error -999, according to the messages I found on the Internet, the reason is that the session deinit property until async shutdown, so As it goes beyond the scope, I finally solved this problem using the deinit session properties manually, so the compiler will not deactivate it in the wrong position:

 class SessionManager { var session:SessionManager? init() { self.session = SessionManager(configuration:URLSessionConfiguration.ephemeral) } private func firstRequest() { guard let session = self.session else {return} session.request(request_url).responseData {response in if let data=response.data { self.secondRequest() } } private func secondRequest() { guard let session = self.session else {return} session.request(request_url).responseData {response in if let data=response.data { self.secondRequest() } //session will no longer be needed, deinit it self.session = nil } } 
+1
Dec 21 '17 at 23:07 on
source share

In addition to what Ramon wrote, there is a third possible reason for getting NSURLErrorDomain -999 cancelled :

You canceled the task while it was running by calling .cancel() for the data task object or because you used .invalidateAndCancel() for the session object. If you are creating a user session with a delegate, you must call .invalidateAndCancel() or .finishTasksAndInvalidate() to resolve the strong link between the session and its delegate, as mentioned in the Apple developer documentation :

The session object maintains a strict reference to the delegate until your application closes or explicitly terminates the session. If you do not cancel the session, your application will lose memory until it terminates.

If you are interested in this kind of logging behavior, I found the following explanation on the Apple Developer Forums :

As an explanation, in iOS 10, we introduced a new logging architecture for the entire system (see the Unified Logging and WWDC 2016 session for details), as well as many subsystems, including CFNetwork. process of transition to this. Until this move is complete, you will encounter some strange extreme cases, such as this one.

+1
Aug 24 '19 at 7:56
source share

I encountered the same error with Alamofire, and this was due to the pinning of the certificate. The certificate is no longer valid, so I had to delete it and add a new one. Hope it helps.

0
Jul 04 '19 at 10:31 on
source share

There are many -999 errors in iOS in our company. I searched around, found a reason, two, for example, the network task was canceled or the certificate is invalid. But I checked our code, these two are not possible. I use Alamofire which uses URLSession. Fortunately, the network of Android applications in our company is normal. So, we will check the difference. We found that the http request from iOS is Http2.0 and Android is Http1.1. Thus, we force the backend http support version to http1.1, then the number of errors -999 decreases !!!

I think there might be some kind of error in the Apple URLSession. Check the New NSURLSession link for each DataTask iteration? for some details

0
Jul 26 '19 at 3:47
source share

I was getting this error in the iOS version of the Xamarin app. Iโ€™m not sure what the main reason is, but in my case I managed to get around it using the post method instead of get for something that passes the server context in the request body - which in any case makes more sense. The Android / Windows / service all processes GET with content, but on iOS, the application partially stops responding, and then posts 999 NSUrlErrorDomain material to the log. Hope this helps someone else run into this. I assume the network code is stuck in a loop, but could not see the code in question.

0
12 sept '19 at 19:39
source share

It turns out that for my Cordova project (or similar) this was a plugin issue. Make sure you donโ€™t miss any plugins and make sure they are installed correctly, without any problems.

The easiest way to check this is to simply start again by re- creating the Cordova project ( cordova create <path> ) along with the required platforms ( cordova platform add <platform name> ) and adding each plugin with a detailed flag (--verbose) so that you can see if something went wrong in the console log while loading the plugin, adding it to the project and installing for each platform ( cordova plugin add cordova-plugin-device --verbose )

Summary: cordova create <path> cordova platform add <platform name> cordova plugin add cordova-plugin-device --verbose

0
01 Oct '19 at 8:03
source share



All Articles