0

我对 iOS 应用程序开发真的很陌生。我现在正在将 FB 集成到我的应用程序中。我按照 fb_developer (https://developers.facebook.com/docs/mobile/ios/build/) 的教程进行操作。

这是我的应用程序 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];
}

}

4

1 回答 1

0

您的应用程序不是唯一在设备上使用 FB 的应用程序...可能还有其他几个应用程序使用 FB 信息...如果您想在您的应用程序中从 FB 注销,则只需从用户默认值中删除访问令牌(因为它发生在代码中的 fbDidLogout 方法中)......

于 2012-07-15T21:19:53.647 回答