Facebook Connect for iOS: dialogDidComplete response differentiation

I was wondering how to differentiate between the user tapping submit or skip in the inline post-to-stream FBDialog. Anyone know what to test for?

I am using the latest iOS Facebook Connect in a iOS 4.2 environment.

 * Called when a UIServer Dialog successfully return.
- (void)dialogDidComplete:(FBDialog *)dialog {
    if user tapped submit and post was successful
        alert user of successful post

    if user tapped "skip" (cancel equivalent)
        do not display alert


As Fede and kennbrodhagen said, this looks like the easiest way (until Facebook fixes this bug):

- (void) dialogCompleteWithUrl:(NSURL*) url
    if ([url.absoluteString rangeOfString:@"post_id="].location != NSNotFound) {
        //alert user of successful post
    } else {
        //user pressed "cancel"

My understanding is that

- (void)dialogDidNotComplete:(FBDialog *)dialog;

would be called for the skip.

I haven't tested this theory though.

Edit: I tested it now, and my theory is wrong. The code looks like the dialog should call

- (void)dialogDidNotCompleteWithUrl:(NSURL *)url

on your delegate, but it practise it seems to not do so, as the web page is returning fbconnect://success for a press of the "skip" button. This sounds like a bug to me.

I did some experimentation and it seems that when the post is submitted you will get two callbacks: dialogCompleteWithUrl and then dialogDidComplete. When the post is skipped, you will only receive the dialogDidComplete callback.

You could trigger your success alert on the dialogCompleteWithUrl callback. If you wanted to wait until you received the dialogDidComplete callback you could save some state during the dialogCompleteWithUrl callback and then based on that state fire your alert in dialogDidComplete.

During my test the url I received during dialogCompleteWithUrl was of the form "fbconnect://success/?post_id=1627754863_182914058401072"

So if need be you could even peek at this value to further confirm your success, although I expect that if the post really did fail (as opposed to a skip) you will get one of the fail callbacks instead.

Hello I just follow link by @Oh Danny Boy and I found this solution

from this thread : http://forum.developers.facebook.net/viewtopic.php?pid=303257#p303257 Fixed this by adding the following to webViewDidFinishLoad: in FBDialog.m

[_webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByName('cancel')[0].onclick = function onclick(event) { window.location.href = 'fbconnect://cancel'; return false;}"];

This makes the cancel button correctly call "fbconnect://cancel" rather than "fbconnect://success".

- (void)webViewDidFinishLoad:(UIWebView *)webView {
  [_webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByName('cancel')[0].onclick = function onclick(event) { window.location.href = 'fbconnect://cancel'; return false;}"];

  [_spinner stopAnimating];
  _spinner.hidden = YES;

  self.title = [_webView stringByEvaluatingJavaScriptFromString:@"document.title"];
  [self updateWebOrientation];

Its works fine:

But There is one more issue If Facebook Change html then this code will no longer work. My solution to this problem is that :

Instead of putting JavaScript statically just get it from server at regular interval or similer mechanism

[_webView stringByEvaluatingJavaScriptFromString://We need to control this javascript from server//];

so in future we can change this javascript instead of updating whole application.

I hope in future this bug will be solved http://bugs.developers.facebook.net/show_bug.cgi?id=5958

Need Your Help

Full text search in HTML ignoring tags / &

javascript html tags full-text-search highlighting

I've recently seen a lot of libraries for searching and highlighting terms within an HTML page. However, every library I saw has the same problem, they can't find text partly encased in an html tag...

AWS Lambda API gateway with Cognito - how to use IdentityId to access and update UserPool attributes?

aws-lambda aws-api-gateway amazon-cognito

OK I am now days into this and have made significant progress but am still completely stumped about the fundamentals.