Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7875895
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:04:36+00:00 2026-06-03T03:04:36+00:00

I have used this method for logout facebook in app – (void)fbDidLogout { //

  • 0

I have used this method for logout facebook in app

- (void)fbDidLogout {
    // Remove saved authorization information if it exists
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    if ([defaults objectForKey:@"FBAccessTokenKey"]) {
        [defaults removeObjectForKey:@"FBAccessTokenKey"];
        [defaults removeObjectForKey:@"FBExpirationDateKey"];
        [defaults synchronize];
    }
    NSLog(@"logout success!");
}

This method has been invoked, but when I relaunch app the facebook still know about my latest authorization.

My full implementation

I create singleton object for facebook instance.

this is my manager .h

#import <Foundation/Foundation.h>
#import "FBConnect.h"

@interface FacebookManager : NSObject <FBSessionDelegate> {
    Facebook *facebook;
}
@property (nonatomic, strong) Facebook *facebook;

+ (FacebookManager *)sharedInstance;
- (void)initWithAppID:(NSString *)appID;

@end

this is singleton facebookmanager .m

#import "FacebookManager.h"

@implementation FacebookManager
@synthesize facebook;

static FacebookManager *_sharedInstance = nil;

+ (FacebookManager *)sharedInstance {
    @synchronized(self) {
        if (!_sharedInstance) {
            _sharedInstance = [[FacebookManager alloc] init];
        }
    }
    return _sharedInstance;
}

- (void)initWithAppID:(NSString *)appID {
    facebook = [[Facebook alloc] initWithAppId:appID andDelegate:self];
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    if ([defaults objectForKey:@"FBAccessTokenKey"]
        && [defaults objectForKey:@"FBExpirationDateKey"]) {
        facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"];
        facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"];
    }
    if (![facebook isSessionValid]) {
        [facebook authorize:nil];
    }
}

- (void)fbDidLogout {
    // Remove saved authorization information if it exists
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    if ([defaults objectForKey:@"FBAccessTokenKey"]) {
        [defaults removeObjectForKey:@"FBAccessTokenKey"];
        [defaults removeObjectForKey:@"FBExpirationDateKey"];
        [defaults synchronize];
    }
    NSLog(@"logout success!");
}

@end

in appDelegate I make next:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

    fbManager = [FacebookManager sharedInstance];
    [fbManager initWithAppID:@"myappid"];

... (some other code)

}

also add this code to app delegate:

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
    return [fbManager.facebook handleOpenURL:url]; 
}

- (void)fbDidLogin {
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setObject:[fbManager.facebook accessToken] forKey:@"FBAccessTokenKey"];
    [defaults setObject:[fbManager.facebook expirationDate] forKey:@"FBExpirationDateKey"];
    [defaults synchronize];    
}

In other view controller I call this method for logout:

- (IBAction)logoutFacebook:(id)sender {
    FacebookManager *fbManager = [FacebookManager sharedInstance];
    [fbManager.facebook logout];
}

also in plist I have add needed url scheme.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T03:04:37+00:00Added an answer on June 3, 2026 at 3:04 am

    That seems to be the way the ios sdk api with sso/oauth 2.0 works. I have not been able to logout completely even after clearing the tokens and I have not been able to switch users from the App. Got to go to the FB app to switch users

    As a workaround, change the line in Facebook.m and disable the safariAuth

    // [self authorizeWithFBAppAuth:YES safariAuth:YES];

     [self authorizeWithFBAppAuth:NO safariAuth:NO]
    

    But then you have to type in the username and password everytime you authorize.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem when call applet method from javascript.. I used this function
I have written a login form, in this I have used, form and method
I am creating a rails app and have used this code in one of
Is it a bug? I remember to have used this method successfully in the
I have used this code in my AS3 document class to remove all objects
I have used this method in the past to detect if the silent switch
I have used this code to load data from a plist. -(void)loadOrCreateData { NSLog(@Start
I have used this code for extracting urls from web page.But in the line
I have used this effect before, everything is in order (As far as I
I have used this query to alter the table field: ALTER TABLE `recordstudent` CHANGE

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.