views:

305

answers:

2

Hi

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 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 thedialogDidSucceedmethod 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:)

A: 

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;
  }
}
Mike
Hi Mike. I see your point. I tried manually calling [self dismissWithSuccess:YES animated:YES] no luck. I tried stepping through the above method and, like you, I never get other URLs than the prompt_feed one. I tried downloading a few examples from tutorials etc. As soon as I modify them to use the FBStreamDialog it hangs on account of incorrect delegate methods.This renders FBConnect useless for my purpose, which is to post data from my app to the users wall.Are there any, "more mature", components out there for doing this?
RickiG
A: 

Facebook has fixed this issue, as you can see from their post at:

http://bugs.developers.facebook.com/show_bug.cgi?id=10531

Edilator
Hi Edilator Thanks ;) I guess the best way of going about this is to close the question.
RickiG