I used Facebook Connect for another project with relatively few problems, however in my current project it seems like when I call [facebook logout]; It does not delete user data. If I then restart the application, I have the following in the didFinishLaunchingWithOptions function:
facebook = [[Facebook alloc] initWithAppId:@"XXXXXXXXXXXXX" andDelegate:self]; NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; if([defaults objectForKey:@"FBAccessTokenKey"] && [defaults objectForKey:@"FBExpirationDateKey"]){ facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"]; facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"]; } NSLog(@"startup login"); [self loginToFacebook];
My loginToFacebook function is as follows:
- (void)loginToFacebook { NSLog(@"Logging into facebook"); //set up facebook and login in automatically if possible NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; if([defaults objectForKey:@"FBAccessTokenKey"] && [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]; } }
As far as I know, this time I will be asked to log in with my email and password. I mainly use the simulator, so the Facebook application is not the reason, but in the Facebook.h class I changed
[self authorizeWithFBAppAuth:NO safariAuth:YES];
to
[self authorizeWithFBAppAuth:NO safariAuth:NO];
However, it happens that the facebook window briefly flashes and disappears, as I would expect when I already log into the system. Then it loads my identifier, name, friend list, etc. from my previous login details. I was no longer able to change users! I must add that I have the following code that prints accordingly to "logout":
- (void)fbDidLogout{ NSLog(@"Logged out of facebook"); }
... which is displayed on the console when [facebook logout] is called. I also have the correct URL schemes, so there is no problem.
As I said, I have work on another application, but I donβt see what I could lose sight of this time. I welcome any suggestion as I suspect this is something ridiculously simple.
Edit: I just tested it on the device, and trying to log in to Facebook leads to the application crashing. I suspect this because he is trying to log in using "saved" information, which is not there, because I have not logged in to the device yet. I am still investigating, but again, if someone sees a clear flaw, I would be very grateful.
Edit2: I tried to delete cookies using the safecase example. I also print all cookies during a) didFinishLaunchingWithOptions and b) during fbDidLogout, and I get the following:
a) `2012-05-18 10: 40: 40.665 MyApp [15545: 17003] (" ",
"<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>", "<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>", "<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>", "<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>", "<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>", "<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>", "<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>", "<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>"
) `
b) 2012-05-18 10:41:16.530 MyApp[15545:17003] ( )
Since it changes to empty, I would suggest that they are deleted. But when you re-open the application, they all reappear.
Edit3: The only way I found is to delete all cookies immediately after opening the application, however this means that the user must log in every time, even if they left themselves in the log the last time they had the application open. This is a temporary solution at the moment, I'm still not sure why it does not work as it should.