title: iOS - Facebook Connect logout not deleting login details?
body: <p>I have used Facebook Connect on another project with relatively few problems, however on my current project it seems that when I call <code>[facebook logout];</code> it doesn't remove the users details. If I then restart the app, I have the following in the didFinishLaunchingWithOptions function:</p>
  
  <pre><code>facebook = [[Facebook alloc] initWithAppId:@"XXXXXXXXXXXXX" andDelegate:self];
  NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  
  if([defaults objectForKey:@"FBAccessTokenKey"]
     &amp;&amp; [defaults objectForKey:@"FBExpirationDateKey"]){
      facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"];
      facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"];
  
  }
  
      NSLog(@"startup login");
      [self loginToFacebook];//attempt to login automatically on startup
  </code></pre>
  
  <p>My loginToFacebook function is this:</p>
  
  <pre><code>- (void)loginToFacebook
  {
      NSLog(@"Logging into facebook");
      //set up facebook and login in automatically if possible
      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]){
  
          //get permissions that user will need to agree to us using
          NSArray *permissions = [[NSArray alloc] initWithObjects:
                                  @"user_likes",@"read_friendlists",@"offline_access", @"publish_stream",
                              nil];
          //authorise our login
          [facebook authorize:permissions];
          [permissions release];
      }
      else
      {
          [facebook authorize:nil];
      }
  }
  </code></pre>
  
  <p>As far as I am concerned, this time I should be prompted to login with my email and password.
  I am mostly using the simulator so the Facebook app itself is not the cause, and in the Facebook.h class I have changed </p>
  
  <pre><code>[self authorizeWithFBAppAuth:NO safariAuth:YES];
  </code></pre>
  
  <p>to</p>
  
  <pre><code>[self authorizeWithFBAppAuth:NO safariAuth:NO];
  </code></pre>
  
  <p>However what happens is that the facebook window briefly flashes up and disappears, as I would expect it to when I am already logged in. It then loads my id, name, friends list etc from my previous login details. It's no longer possible for me to change users! I should add that I have the following code which prints accordingly on 'logout':</p>
  
  <pre><code>- (void)fbDidLogout{
      NSLog(@"Logged out of facebook");
  }
  </code></pre>
  
  <p>...which prints to the console when [facebook logout] is called. I also have the correct url schemes in place so there is no problem there.</p>
  
  <p>As I say I've got this working on another app, but I can't see what I could've overlooked this time. 
  I welcome any suggestion, as I suspect it's something ridiculously simple. </p>
  
  <p>Edit: I've just tested it out on a device, and the attempt to login to Facebook causes the app to crash. I suspect it's because it's attempting to login using 'stored' info, which doesn't exist because I haven't logged in on the device yet. I'm still investigating but again, if any  can see an obvious flaw I'd be very grateful.</p>
  
  <p>Edit2:I've tried removing cookies using safecase's example. I also print out all of the cookies during a) didFinishLaunchingWithOptions and b) during fbDidLogout, and I get the following:</p>
  
  <p>a)
  `2012-05-18 10:40:40.665 MyApp[15545:17003] (
      "",</p>
  
  <pre><code>"&lt;NSHTTPCookie version:0 name:\"c_user\" value:\"634361620\" expiresDate:2012-06-17 09:34:33 +0000 created:2012-05-18 09:34:34 +0000 (3.59026e+08) sessionOnly:FALSE domain:\".facebook.com\" path:\"/\" isSecure:TRUE&gt;",
  "&lt;NSHTTPCookie version:0 name:\"csm\" value:\"2\" expiresDate:2012-06-17 09:34:33 +0000 created:2012-05-18 09:34:34 +0000 (3.59026e+08) sessionOnly:FALSE domain:\".facebook.com\" path:\"/\" isSecure:FALSE&gt;",
  "&lt;NSHTTPCookie version:0 name:\"datr\" value:\"gxe2T8ZyBzMGb5w3LS29Q0kJ\" expiresDate:2014-05-18 09:34:33 +0000 created:2012-05-18 09:34:34 +0000 (3.59026e+08) sessionOnly:FALSE domain:\".facebook.com\" path:\"/\" isSecure:FALSE&gt;",
  "&lt;NSHTTPCookie version:0 name:\"locale\" value:\"en_US\" expiresDate:2012-05-25 09:36:43 +0000 created:2012-05-18 09:36:44 +0000 (3.59027e+08) sessionOnly:FALSE domain:\".facebook.com\" path:\"/\" isSecure:FALSE&gt;",
  "&lt;NSHTTPCookie version:0 name:\"lu\" value:\"RgayA7CMIlsAl-lOD2-Y-O3g\" expiresDate:2014-05-18 09:34:33 +0000 created:2012-05-18 09:34:34 +0000 (3.59026e+08) sessionOnly:FALSE domain:\".facebook.com\" path:\"/\" isSecure:FALSE&gt;",
  "&lt;NSHTTPCookie version:0 name:\"m_user\" value:\"0%3A0%3A0%3A0%3Av_1%2Cajax_1%2Cwidth_320%2Cpxr_1%2Cgps_1%3A1337333673%3A2\" expiresDate:2012-08-16 09:34:33 +0000 created:2012-05-18 09:34:34 +0000 (3.59026e+08) sessionOnly:FALSE domain:\".facebook.com\" path:\"/\" isSecure:FALSE&gt;",
  "&lt;NSHTTPCookie version:0 name:\"s\" value:\"Aa4WdKU-oOFathmK\" expiresDate:2012-06-17 09:34:33 +0000 created:2012-05-18 09:34:34 +0000 (3.59026e+08) sessionOnly:FALSE domain:\".facebook.com\" path:\"/\" isSecure:TRUE&gt;",
  "&lt;NSHTTPCookie version:0 name:\"xs\" value:\"125%3AFFIWXjAXDXUMmw%3A2%3A1337333673\" expiresDate:2012-06-17 09:34:33 +0000 created:2012-05-18 09:34:34 +0000 (3.59026e+08) sessionOnly:FALSE domain:\".facebook.com\" path:\"/\" isSecure:TRUE&gt;"
  </code></pre>
  
  <p>)`</p>
  
  <p>b)
  <code>2012-05-18 10:41:16.530 MyApp[15545:17003] (
  )</code></p>
  
  <p>Since it changes to empty, I would assume they are deleted. But on reopening the app, they are all there again.</p>
  
  <p>Edit3: The only way around this I have found is to delete all cookies as soon as the application opens, however this means the user has to login every time, even if they left themselves logged in the last time they had the app open. It's a temporary fix for the moment, I'm still not sure why it's not working as it should be.</p>