Reputation: 4401
I use facebook sdk in my app. I done log in with facebook simple like this:
FBLoginView *loginview = [[FBLoginView alloc] initWithPermissions:[NSArray arrayWithObject:@"publish_actions"]];
UIImage *loginImage = [UIImage imageNamed:@"login_facebook_button.png"];
// loginview.backgroundColor = [UIColor redColor];
loginview.frame = CGRectMake(15, 294, loginImage.size.width, loginImage.size.height);
for (id obj in loginview.subviews)
{
if ([obj isKindOfClass:[UIButton class]])
{
UIButton * loginButton = obj;
[loginButton setBackgroundImage:loginImage forState:UIControlStateNormal];
[loginButton setBackgroundImage:nil forState:UIControlStateSelected];
[loginButton setBackgroundImage:nil forState:UIControlStateHighlighted];
[loginButton sizeToFit];
}
if ([obj isKindOfClass:[UILabel class]])
{
UILabel * loginLabel = obj;
loginLabel.text = [Lang get:@"SIGN_IN_WITH_FACEBOOK"];
loginLabel.textAlignment = UITextAlignmentCenter;
[loginLabel setTextColor:[UIColor colorWithRed:228.0/255.0 green:228.0/255.0 blue:228.0/255.0 alpha:1.0]];
[loginLabel setShadowColor:[UIColor colorWithRed:127.0/255.0 green:127.0/255.0 blue:127.0/255.0 alpha:1.0]];
loginLabel.frame = CGRectMake(0, 0, loginImage.size.width, loginImage.size.height);
}
}
loginview.delegate = self;
[self.view addSubview:loginview];
I had logged normally. But when i try to log out using this
[FBSession.activeSession closeAndClearTokenInformation];
I get exception and it don't write what is actually wrong. My app crash at this point.
However it actual clears token because after crash it had logged out.
So what i am doing wrong ?
Thanks
Upvotes: 1
Views: 5049
Reputation: 2648
FBSession* session = [FBSession activeSession];
[session closeAndClearTokenInformation];
[session close];
[FBSession setActiveSession:nil];
NSHTTPCookieStorage* cookies = [NSHTTPCookieStorage sharedHTTPCookieStorage];
NSArray* facebookCookies = [cookies cookiesForURL:[NSURL URLWithString:@"https://facebook.com/"]];
for (NSHTTPCookie* cookie in facebookCookies) {
[cookies deleteCookie:cookie];
}
Upvotes: 12
Reputation: 38239
Use this:
- (void)logout:(id<FBSessionDelegate>)delegate {
self.sessionDelegate = delegate;
[_accessToken release];
_accessToken = nil;
[_expirationDate release];
_expirationDate = nil;
NSHTTPCookieStorage* cookies = [NSHTTPCookieStorage sharedHTTPCookieStorage];
NSArray* facebookCookies = [cookies cookiesForURL:[NSURL URLWithString:@"http://login.facebook.com"]];
for (NSHTTPCookie* cookie in facebookCookies) {
[cookies deleteCookie:cookie];
}
if ([self.sessionDelegate respondsToSelector:@selector(fbDidLogout)]) {
[_sessionDelegate fbDidLogout];
}
}
Refer ios-facebook-connect-logout-not-deleting-login-details link.
Upvotes: 0