In my app Am using Facebook. Am integrated FB with my app.
Login also happening correctly. But when am trying to logout it is showing logout successful in fbDidLogout but when we try to login again means it is just showing login page and logging with previously entered username and password.
How can we logout correctly.
Any one can help or suggest
Here is my code
This is Login Logout Button Action
- (IBAction)LoginOrLogout
{
// If the user is not connected (logged in) then connect. Otherwise logout.
if (!isConnected)
{
// Set the permissions.
// Without specifying permissions the access to Facebook is imposibble.
permissions = [[NSArray arrayWithObjects:@"read_stream", @"publish_stream", nil] retain];
// Set the Facebook object we declared. We’ll use the declared object from the application
// delegate.
facebook = [[Facebook alloc] initWithAppId:@"329082513817407" andDelegate:self];
[btnPublish setHidden:NO];
[messageTextField setHidden:NO];
[facebook authorize:permissions];
// Change the lblUser label's message.
[lblUser setText:@"Please wait..."];
isConnected = YES;
[self setLoginButtonImage];
}
else
{
[facebook logout:self];
[messageTextField setHidden:YES];
[lblUser setText:@"Tap on the Login to connect to Facebook"];
isConnected = NO;
[self setLoginButtonImage];
}
}
These are the other methods
-(void)fbDidLogin
{
// Save the access token key info.
[self saveAccessTokenKeyInfo];
// Get the user's info.
[facebook requestWithGraphPath:@"me" andDelegate:self];
}
-(void)fbDidNotLogin:(BOOL)cancelled
{
UIAlertView *al = [[UIAlertView alloc] initWithTitle:@"Tonify" message:@"Login cancelled." delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[al show];
[self LoginOrLogout];
}
-(void)fbDidLogout
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSLog(@"defaults fbDidLogout ........%@",defaults);
if ([defaults objectForKey:@"FBAccessTokenKey"])
{
[defaults removeObjectForKey:@"FBAccessTokenKey"];
[defaults removeObjectForKey:@"FBExpirationDateKey"];
[defaults synchronize];
}
NSLog(@"defaults fbDidLogout ........%@",defaults);
NSLog(@"logout success!");
// Keep this for testing purposes.
NSLog(@"Logged out Succes");
// Hide the publish button.
[btnPublish setHidden:YES];
}
Use this method: