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 に答える