3
votes

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.

2

2 Answers

7
votes

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.

2
votes

Well, the good news is that peeps at Facebook agree with your fix:

(in response to FB bug #168127053284477)


  - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
     // 102 == WebKitErrorFrameLoadInterruptedByPolicyChange
-    if (!([error.domain isEqualToString:@"WebKitErrorDomain"] && error.code == 102)) {
+    // -999 == "Operation could not be completed", note -999 occurs when the user clicks away before
+    // the page has completely loaded, if we find cases where we want this to result in dialog failure
+    // (usually this just means quick-user), then we should add something more robust here to account
+    // for differences in application needs
+    if (!(([error.domain isEqualToString:@"NSURLErrorDomain"] && error.code == -999) ||
+          ([error.domain isEqualToString:@"WebKitErrorDomain"] && error.code == 102))) {
           [self dismissWithError:error animated:YES];
         }
     }