When is Facebook Connect supposed to call its delegate methods?
The Facebook connect code is eluding me a bit. I have no problem doing a login, and a wall post, however, I simply can not figure out how the delegate methods for the FBDialog andFBStreamDialog is supposed to work.
- (void)postToWall {
FBStreamDialog *dialog = [[[FBStreamDialog alloc] init] autorelease];
dialog.delegate = self;
dialog.userMessagePrompt = @"Enter your message:";
dialog.attachment = [NSString stringWithFormat:@"JSONpost code"];
[dialog show];
}
I adhere开发者_如何学JAVA to these protocols in my controller:
<FBDialogDelegate, FBSessionDelegate, FBRequestDelegate>
I then implement the two methods:
- (void) dialogDidCancel:(FBDialog *)dialog {
NSLog(@"Failed");
}
- (void) dialogDidSucceed:(FBDialog *)dialog {
NSLog(@"Success");
}
After I tap "publish" and the postToWall methods is done executing the Facebook "pop up" in the UI is empty, except a small "X" in the top right corner and a "F" (facebook logo) in the top left corner.
The UI will stay there until I tap the "X", this results in the dialogDidCancel
delegate method being called. The post data is showing up on the Facebook page, everything seems to work.
Why is thedialogDidSucceed
method never called? I need this to release my facebook controller and restore the UI back to where the user was before "starting" FB Connect.
Thank You:)
Facebook has fixed this issue, as you can see from their post at:
http://bugs.developers.facebook.com/show_bug.cgi?id=10531
I see where the problem is, but not sure what if anything we can do about it. It happens in the UIWebView Delegate method in the FBDialog class. If you click the Skip button, the request.URL is populated with 'fbconnect:success', it should really be 'fbconnect:cancel' but other people have already pointed out this problem out before. Our problem is that when you click the Publish button, the request.URL should read 'fbconnect:success' however, it ends up containing 'http://www.facebook.com/fbconnect/prompt_feed.php', so, it never calls dismissWithSuccess:YES or dialogDidSucceed.
I can't find anyplace where the Publish button's post URL is set, but if we can change it to fbconnect:success, it might work.
FBDialog.m
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request
navigationType:(UIWebViewNavigationType)navigationType {
NSURL* url = request.URL;
if ([url.scheme isEqualToString:@"fbconnect"]) {
if ([url.resourceSpecifier isEqualToString:@"cancel"]) {
[self dismissWithSuccess:NO animated:YES];
} else {
[self dialogDidSucceed:url];
}
return NO;
} else if ([_loadingURL isEqual:url]) {
return YES;
} else if (navigationType == UIWebViewNavigationTypeLinkClicked) {
if ([_delegate respondsToSelector:@selector(dialog:shouldOpenURLInExternalBrowser:)]) {
if (![_delegate dialog:self shouldOpenURLInExternalBrowser:url]) {
return NO;
}
}
[[UIApplication sharedApplication] openURL:request.URL];
return NO;
} else {
return YES;
}
}
精彩评论