Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

First dialog after authenticating fails immediately and closes dialog

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.

like image 294
Senior Avatar asked Nov 03 '11 21:11

Senior


3 Answers

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..

like image 118
allaire Avatar answered Nov 04 '22 22:11

allaire


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];
}
like image 38
Brian Rothstein Avatar answered Nov 04 '22 20:11

Brian Rothstein


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.

like image 34
Senior Avatar answered Nov 04 '22 20:11

Senior