17

I'm using the latest Facebook SDK on iOS 5. I can use SSO to successfully authenticate the user, and then I attempt to share a link like this:

NSString *appId = [[[NSBundle mainBundle] infoDictionary] 
                                          objectForKey:TSFacebookAppID];

NSMutableDictionary* params = 
[NSMutableDictionary dictionaryWithObjectsAndKeys:
                          appId,                @"app_id",
                          [url absoluteString], @"link
                          title,                @"caption",
                          body,                 @"description",
                          nil];

[facebook dialog:@"feed" andParams:params andDelegate:self];

The first time I attempt this, the dialog appears and immediately closes, calling the dialog:didFailWithError:error delegate method. The error is:

Error Domain=NSURLErrorDomain Code=-999 "The operation couldn’t be completed. (NSURLErrorDomain error -999.)" UserInfo=0x98f2ab0 {NSErrorFailingURLKey=https://m.facebook.com/dialog/feed?link=http%3A%2F%2Fwww.thescore.com%2Fhome%2Farticles%2F184248&description=Nadal%20pulls%20out%20of%20Paris%20to%20focus%20on%20ATP%20finals&access_token=BAABw00HZB06cBALT57lZCM24N4EOtPpOQeCgl7oLUvbHFR0ZAlwgAbPHQ7HANmlBE0aUKVNDmWNYsEqB0wXq28vm4D18T5hLTVDK3x2WjnVjgIVl75RPoOszSB21f4ZD&caption=Article%20from%20ScoreMobile%20for%20iPhone&app_id=124052647629735&redirect_uri=fbconnect%3A%2F%2Fsuccess&sdk=2&display=touch, NSErrorFailingURLStringKey=https://m.facebook.com/dialog/feed?link=http%3A%2F%2Fwww.thescore.com%2Fhome%2Farticles%2F184248&description=Nadal%20pulls%20out%20of%20Paris%20to%20focus%20on%20ATP%20finals&access_token=BAABw00HZB06cBALT57lZCM24N4EOtPpOQeCgl7oLUvbHFR0ZAlwgAbPHQ7HANmlBE0aUKVNDmWNYsEqB0wXq28vm4D18T5hLTVDK3x2WjnVjgIVl75RPoOszSB21f4ZD&caption=Article%20from%20ScoreMobile%20for%20iPhone&app_id=124052647629735&redirect_uri=fbconnect%3A%2F%2Fsuccess&sdk=2&display=touch}

However, subsequent attempts to share the link work fine.

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
Senior
  • 2,259
  • 1
  • 20
  • 31
  • 1
    Yes! I am seeing 100% the same thing. New implementation, iOS5. Very same error. Subsequent attempts work fine. On app restart, attempts work fine because the session is still valid. But if I delete app and install fresh, again the first attempt fails (apparently caused by the SSO auth process somehow?) – Paul Bruneau Nov 04 '11 at 18:08
  • It's the same story with iOS 7! Except the authentication fails everytime – tipycalFlow Sep 25 '13 at 12:12

6 Answers6

10

Just an update for everyone, it's finally assigned to somebody at Facebook: https://developers.facebook.com/bugs/168127053284477 - hopefully it will be fixed soon.

Meanwhile, somebody sent a pull request on github with a fix: https://github.com/facebook/facebook-ios-sdk/pull/436

Hope it helps someone, as I was still facing the same bug..

allaire
  • 5,995
  • 3
  • 41
  • 56
  • This bug is still not fixed in the latest facebook-ios-sdk as of Sep 10, 2012. I had to switch to an older version (facebook iphone sdk) to get this basic thing to work. Why did they have to break core functionality? – Arunabh Das Sep 11 '12 at 04:56
8

I was also occasionally getting this -999 NSURLDomainError when trying to bring up the facebook post window. I took the strategy of ignoring the error code as Senior mentions in the comments.

The reason I don't feel so bad about this fix is that the FBLoginDialog actually already ignores this error. Check out the code in github:

https://github.com/facebook/facebook-ios-sdk/blob/master/src/FBLoginDialog.m#L85

So to be specific, here's what my webView:didFailLoadWithError method looks like in FBDialog.m now:

- (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];
}
Brian Rothstein
  • 1,312
  • 10
  • 20
4

In FBDialog.m, change this:

UIWindow* window = [UIApplication sharedApplication].keyWindow;
if (!window) {
    window = [[UIApplication sharedApplication].windows objectAtIndex:0];
}

To this:

UIWindow* window = [[UIApplication sharedApplication].windows objectAtIndex:0];

Problem solved! For me, at least.

Senior
  • 2,259
  • 1
  • 20
  • 31
  • I think this is a different problem. I saw this answer on another thread and had already tried it to no effect. The error we are seeing here is a webview rendering error that comes from Facebook's server (see the error in the log posted by the original poster). Hmm, you are the original poster. Curious. – Paul Bruneau Nov 07 '11 at 14:39
  • 4
    I ignore the error by changing line 413 of FBDialog.m to: if (!(([error.domain isEqualToString:@"WebKitErrorDomain"] && error.code == 102) || error.code == -999)), and now it works. – Senior Nov 07 '11 at 19:24
  • I would guess that it never worked--you just weren't seeing the problem because you were already logged into facebook. In my testing, the problem only occurs when first logging in. – Paul Bruneau Nov 07 '11 at 21:17
  • I tested it pretty thoroughly; I have a sneaking suspicion that it's a race condition. I have a UIWebView onscreen in my app when I attempt to launch the dialog, and then Facebook presents its dialog using a UIWebView, so perhaps they're conflicting. – Senior Nov 08 '11 at 15:58
  • I was referring to your UIWindow change above, not to your test for error.code == -999. I was also thinking some kind of race, or perhaps the iPhone app is trying to display information before the login on the facebook server is complete or something, but that's why I tested it with a delay and still had no success. I have yet to try your -999 filter. – Paul Bruneau Nov 08 '11 at 16:12
  • Yeah, I was referring to the UIWindow change too. Try the -999 filter, it seems to work, although hopefully without any negative consequences from ignoring the error. – Senior Nov 08 '11 at 19:41
  • Hi Senior-I tried the -999 filter finally and it seems to work fine here. It's better than my "load it twice" workaround because then the user doesn't see two dialogs appear in rapid succession. Thanks! – Paul Bruneau Nov 29 '11 at 15:55
  • Just wanted to say Senior's comment above (the line 413 change) also fixed our problem. We also happened to have a UIWebView on the screen so it does seem like they conflict. – ChrisJP Feb 03 '12 at 21:28
1

This has been fixed with the 3.0 SDK, so I'm going to close this question. Solution: upgrade the SDK to 3.0.

Senior
  • 2,259
  • 1
  • 20
  • 31
1

Until facebook patch their SDK, I did'nt find any better solution than this one :

- (void)dialog:(FBDialog *)dialog didFailWithError:(NSError *)error{

    if([error code] == -999){
        DLog(@"Error -999 found re-open webview");

        [facebook dialog:@"apprequests"
               andParams:_dialogParams
             andDelegate:self];

    }else{
        DLog(@"Error opening facebook dialog : %@", [error description]);
    }
}
mcflyfr
  • 61
  • 5
  • this approach does not seem to work because it redirect me to same log in dialog once again so it ends up in an infinite loop – Ilker Baltaci Jul 16 '12 at 09:00
0

I traced it back as far as I think I can in dialog.m, which is line 414--dialog.m is sending the URLRequest for the dialog in a web view, but the web view is apparently getting an error back from Facebook's server.

I tried calling my [facebook dialog:@"feed"...] code after a 10 second delay after authentication, no dice--same error.

So then just for grins, I called my feed code from -dialog:didFailWithError... after checking to see if it was error -999. It works fine from that call. ????

Paul Bruneau
  • 1,026
  • 1
  • 9
  • 15