11

アクティブ セッションを閉じるにはどうすればよいFacebook-iOS-Sdkですか? アプリを起動するたびに、アプリを強制終了した後、以前のログイン セッションの詳細が表示されます。Facebookボタンをクリックすると、すべてを使用しましたが、[appDelegate.session closeAndClearTokenInformation]; [FBSession.activeSession close]; [FBSession.activeSession closeAndClearTokenInformation]アクティブなセッションはまだ閉じていません..クリック時に以前のセッションデータを閉じるにはどうすればよいですか。

以下のコードを使用してクリアしますが、Facebook ボタンをクリックして新しいセッションを開始するたびに、以前の資格情報が返されます。

- (IBAction)buttonClickHandler:(id)sender {

appDelegate = [[UIApplication sharedApplication]delegate];

// this button's job is to flip-flop the session from open to closed
if (appDelegate.session.isOpen) {

    [appDelegate.session closeAndClearTokenInformation];
    [FBSession.activeSession close];
    [FBSession.activeSession  closeAndClearTokenInformation];
    FBSession.activeSession=nil;

} else {
    if (appDelegate.session.state != FBSessionStateCreated) {
        // Create a new, logged out session.
        appDelegate.session = [[FBSession alloc] init];
    }

    // if the session isn't open, let's open it now and present the login UX to the user
    [FBSession.activeSession closeAndClearTokenInformation];
    FBSession.activeSession=nil;
    [FBSession.activeSession openWithBehavior:FBSessionLoginBehaviorForcingWebView

                            completionHandler:^(FBSession *session,

                                                FBSessionState state,

                                                NSError *error) {
                                // and here we make sure to update our UX according to the new session state

                                NSLog(@" state=%d",state);

                                [FBRequestConnection
                                 startForMeWithCompletionHandler:^(FBRequestConnection *connection,
                                                                   id<FBGraphUser> user,
                                                                   NSError *error) {

                                     userInfo = @"";

                                     // Example: typed access (name)
                                     // - no special permissions required
                                     userInfo = user.username;

                                     NSLog(@"string %@", userInfo); 
                                          [self checkfacebook];

                                 }];


                            }];    } 


 }

そしてViewDidLoadで

- (void)viewDidLoad
{
[super viewDidLoad];





AppDelegate *appDelegate = [[UIApplication sharedApplication]delegate];
if (!appDelegate.session.isOpen) {
    // create a fresh session object
    appDelegate.session = [[FBSession alloc] init];


    if (appDelegate.session.state == FBSessionStateCreatedTokenLoaded) {
        // even though we had a cached token, we need to login to make the session usable
        [FBSession.activeSession close];
        FBSession.activeSession=nil;
   }
}



NSHTTPCookieStorage* cookies = [NSHTTPCookieStorage sharedHTTPCookieStorage];
NSArray* facebookCookies = [cookies cookiesForURL:[NSURL URLWithString:@"http://login.facebook.com"]];

for (NSHTTPCookie* cookie in facebookCookies) {
    [cookies deleteCookie:cookie];
}    


}
4

3 に答える 3

28

こんにちはChristianは、次の2つのリンクを参照してください。この2つのリンクを参照してください。developers.facebook

http://developers.facebook.com/docs/reference/ios/3.0/class/FBSession/

http://developers.facebook.com/docs/reference/ios/3.0/class/FBSession/#close

[FBSession.activeSession closeAndClearTokenInformation];
[FBSession.activeSession close];
[FBSession setActiveSession:nil];

問題に関連するこの2つの質問を確認することもできます:-

FacebookグラフAPIのログアウトが機能しない

Facebook iOS SDK 3.1.1「closeAndClearTokenInformation」メソッドが機能しない

それがあなたを助けることを願っています

于 2013-01-21T06:11:38.767 に答える
0

Nitin の Gohel の回答、Swift バージョン:

    FBSession.activeSession().closeAndClearTokenInformation()
    FBSession.activeSession().close()
    FBSession.setActiveSession(FBSession())

あなたが使用することができます

    FBSession.setActiveSession(nil)

ただし、関数はラップされていないオブジェクトを要求するため、「nil」を渡すのは適切なパラメーターではないようです

于 2015-05-14T13:33:20.313 に答える