我对 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];
}
}