Facebook Connect for iOS: dialogDidComplete respon

2020-06-08 06:39发布

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
}

标签: ios facebook
4条回答
forever°为你锁心
2楼-- · 2020-06-08 07:21

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

查看更多
我欲成王,谁敢阻挡
3楼-- · 2020-06-08 07:23

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.

查看更多
爷、活的狠高调
4楼-- · 2020-06-08 07:25

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"
    }
}

查看更多
Animai°情兽
5楼-- · 2020-06-08 07:28

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.

查看更多
登录 后发表回答