title: Facebook's FBConnect SDK issues on iOS
body: <p>I'm using FBConnect sdk in order to publish posts to a user's profile via my application. I'm having a number of problems with this:</p>
  
  <p>When the relevant code runs for the first time on the device, the user is re-directed, as wanted, to the facebook app/website, which asks him to authorize it. if the user authorizes it, it returns back to the application, which pops a "Connect to facebook" view controller which asks the user to log in. this is weird, as the user is already logged in, otherwise how could he authorize the app? but I guess this may be ok, as he hadn't logged in through the app yet. after he logs in, it does nothing. only the second time the code gets run, after he authorized the app, the user gets the posting dialog.<br /><br />
  If the user hadn't authorized the app, when it comes back to my app after the authorization dialog, it asks the user to login ( just as if he authorized ), and does nothing after he had logged in. only the second time the code gets ran, the authorization dialog opens, with the optinos "Authorize"  &amp; "Leave App", instead of "Authorize" &amp; "Don't authorize" / "Allow" &amp; "Don't Allow".</p>
  
  <p>In addition, if the user has deleted his authorization via his account's settings on facebook, instead of just asking him to re-authorize it, a facebook dialog pops ( instead of the post/authorization dialog ), saying: "An error occurred. Please try again later." Trying later doesn't help. it will pop always, even if u restart the app. the only way to make it go away is to re-install the app, which will cause it to re-pop the authoriziation dialog.<br /><br />
  So here's what I want to achieve:</p>
  
  <ol>
  <li>After the user authorizes the app, he wouldn't have to log in again.<br/></li>
  <li>After the user authorizes the app, the posting dialog will pop immedietly, without him having to re-run the code ( which is triggered, btw, with a button ).<br /></li>
  <li>If the user un-authorizes the app, he will be prompted again with the authorization dialog, instead of the error dialog</li>
  <li>If he refused the authorization, I will call a function that displays an error/etc.</li>
  </ol>
  
  <p>Here's the relevant code:</p>
  
  <p><b>MyViewController.m</b></p>
  
  <pre><code>- (void)shareOnFacebook
  {
      Facebook *facebook = [[Facebook alloc] initWithAppId:myAppID];
      [(MyAppDelegate *)[[UIApplication sharedApplication] delegate] setFacebook:facebook];
      [facebook release];
      facebook = [(MyAppDelegate *)[[UIApplication sharedApplication] delegate] facebook];
      NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
      if ([defaults objectForKey:@"FBAccessTokenKey"] &amp;&amp; [defaults objectForKey:@"FBExpirationDateKey"]) {
          facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"];
          facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"];
      }
      if (![facebook isSessionValid]) {
          [facebook authorize:[NSArray arrayWithObjects:@"publish_stream", nil] delegate:(MyAppDelegate *)[[UIApplication sharedApplication] delegate]];
      }
  
       NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
       //Giving the dictionary some parameters for posting defaults
       [facebook dialog:@"feed" andParams:dictionary andDelegate:self]; //Note: we have 2 different delegates! appDelegate for connections &amp; url switching, and self for dialogs
  }
  </code></pre>
  
  <p><b>MyAppDelegate.h</b></p>
  
  <pre><code>@interface MyAppDelegate : NSObject &lt;UIApplicationDelegate, FBSessionDelegate, FBDialogDelegate&gt;
  {  
      Facebook *facebook; // kept for facebook sharing, accessed only from MyViewController although delegate methods are handeled in here
  }
  @property (nonatomic, retain) Facebook *facebook;
  
  @end
  </code></pre>
  
  <p><b>MyAppDelegate.m</b></p>
  
  <pre><code>- (void)fbDidLogin
  {
      NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
      [defaults setObject:[facebook accessToken] forKey:@"FBAccessTokenKey"];
      [defaults setObject:[facebook expirationDate] forKey:@"FBExpirationDateKey"];
      [defaults synchronize];
  }
  
  - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
  {
      return [self.facebook handleOpenURL:url];
  }
  </code></pre>
  
  <p>Is it possible that I'm missing a couple of delegate functions on MyViewController? Because I see for some reason I've marked it as implementing the FBDialogDelegate protocol, although he doesn't implement any function from there.<br /><br />
  I'd be really glad if you guys would help me, as this is extremely frustrating for me. I couldn't find nothing about this on the internet, and I feel like im drowning in here.<br /><br />Tnx in advance!</p>