NSURLErrorDomain error code -999 in iOS
I've been trying to use Corona SDK's Facebook API to post the score on the game I'm developing on facebook. However, I'm having a problem with it. During the first time I try to post to facebook, I get this error after login and user authentication:
NSURLErrorDomain error code -999
Then, it won't post on facebook. What are possible causes of this error and how can I address it? I tried searching the web but couldn't find information about it. Thanks in advance.
By the way, I am not using webview on my app. Just the widget api and a show_dialog listener in my Facebook class.
Solution 1:
The error has been documented on the Mac Developer Library(iOS docs)
The concerned segment from the documentation will be:
URL Loading System Error Codes
These values are returned as the error code property of an NSError object with the domain “NSURLErrorDomain”.
enum { NSURLErrorUnknown = -1, NSURLErrorCancelled = -999, NSURLErrorBadURL = -1000, NSURLErrorTimedOut = -1001,
As you can see; -999
is caused by ErrorCancelled
. This means: another request is made before the previous request is completed.
Solution 2:
hjpotter92 is absolutely right, I just want to provide solution for my case. Hopefully it is useful for you as well. Here is my situation:
On log in page > press log in > pop up loading dialog > call log in service > dismiss dialog > push another screen > call another service --> cause error -999
To fix it, I put a delay between dismissing dialog and pushing 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 issue happens on iOS 7 only.
Solution 3:
Just wanted to add here, when receiving a -999 "cancelled"
the problem usually is one of two things:
- You're executing the exact same request again.
- You're maintaining a weak reference to your
manager
object that gets deallocated prematurely. (Create strong reference)