Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook dialog failed with error: The operation couldn’t be completed. (NSURLErrorDomain error -999.)

I am using the facebook api for ios and i am using facebook dialogs to post.

The basic idea is that i have a button to post that calls a method and ask if you are logged in to post right away or to perform the log in and then post. When the second scenario occurs i can't post right after log in to facebook so i have to tap the button and call the method again so i can post.

The error that facebook sends me says: The operation couldn’t be completed. (NSURLErrorDomain error -999.)

I have read here in stack about it and it says:

According to "Foundation Constants Reference", error code -999 means "NSURLErrorCancelled".

Description:

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 iOS 2.0 and later. Declared in NSURLError.h.

The question is why facebook is sending me this and how can i solve it?

If more code is necessary i can put it.

Thanks in advance.

like image 299
Julian Osorio Avatar asked Dec 31 '25 16:12

Julian Osorio


1 Answers

The way I fixed this was I changed FBDialog.m to ignore error code -999 like this

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
// 102 == WebKitErrorFrameLoadInterruptedByPolicyChange
NSLog(@"FBDialog webView didFailLoadWithError:%@ %d",error.domain,error.code);
if ([error.domain isEqualToString:@"NSURLErrorDomain"] && error.code == -999)
    return;

if ([error.domain isEqualToString:@"WebKitErrorDomain"] && error.code == 102)
    return;

[self dismissWithError:error animated:YES];
}

What's interesting is that FBLoginDialog was already ignoring both error code 102 and -999 whereas FBDialog was only ignoring 102. See for yourself: https://github.com/facebook/facebook-ios-sdk/blob/master/src/FBLoginDialog.m#L85

I don't know if this is the best solution, but I feel slightly more confident about it since another piece of the Facebook sdk code already ignores the same error.

like image 90
Brian Rothstein Avatar answered Jan 02 '26 04:01

Brian Rothstein