2012-07-15 44 views
0

我對iOS應用程序開發真的很陌生。我現在將FB集成到我的應用程序中。我遵循fb_developer的教程(https://developers.facebook.com/docs/mobile/ios/build/)。爲什麼在iOS版的FB SSO中看不到註銷按鈕?

以下是我的app delegate.m中的代碼。我想知道爲什麼我看不到屏幕上的註銷按鈕,我無法註銷。

#import "FBtestAppDelegate.h" 
#import "FBtestViewController.h" 

@implementation FBtestAppDelegate 

@synthesize window = _window; 
@synthesize viewController=_viewController; 
@synthesize facebook; 



- (BOOL)application:(UIApplication *)application 
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
// Add the logout button 
UIButton *logoutButton = [UIButton buttonWithType:UIButtonTypeRoundedRect]; 
logoutButton.frame = CGRectMake(40, 40, 200, 40); 
[logoutButton setTitle:@"Log Out" forState:UIControlStateNormal]; 
[logoutButton addTarget:self action:@selector(logoutButtonClicked) 
     forControlEvents:UIControlEventTouchUpInside]; 
[self.viewController.view addSubview:logoutButton]; 


// Override point for customization after application launch. 
self.window.rootViewController = self.viewController; 
[self.window makeKeyAndVisible]; 

facebook = [[Facebook alloc] initWithAppId: @"400478970009544" 
           andDelegate:self]; 

NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; 
if ([defaults objectForKey:@"FBAccessTokenKey"] 
    && [defaults objectForKey:@"FBExpirationDateKey"]){ 
    facebook.accessToken = [defaults objectForKey:@"FBAcccessTokenKey"]; 
    facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"]; 
} 

// This part, the authorize method will bring you to the authorization page        
if (![facebook isSessionValid]) 
    { 
     [facebook authorize:nil]; 
    } 

return YES; 
} 


- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url 
    sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { 
return [facebook handleOpenURL:url]; 
} 


// Save the user credential, specifically the access token and the expiration date to the  user defaults 
- (void)fbDidLogin { 
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; 
[defaults setObject:[facebook accessToken] forKey:@"FBAcessTokenKey"]; 
[defaults setObject:[facebook expirationDate] forKey:@"FBExpirationDateKey"]; 
[defaults synchronize]; 

}

//方法時註銷按鈕被按下

- (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]; 
} 

}

回答

0

的應用無法使用設備上的FB唯一的應用程序所調用...可能還有其他幾個應用程序使用FB信息....如果您想在應用程序中從FB註銷,那麼只需從用戶默認值中刪除訪問令牌(因爲它發生在fbDidLogout方法中d在你的代碼中)...