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