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

嗨克里斯蒂安可能在下面两个链接它的帮助你请重新引用这两个链接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];

您还可以检查与您的问题相关的这两个问题:-

Facebook graph api注销不起作用

Facebook iOS SDK 3.1.1“closeAndClearTokenInformation”方法不起作用

希望它可以帮助你

于 2013-01-21T06:11:38.767 回答
4

打电话后

    [FBSession.activeSession closeAndClearTokenInformation];

使用以下清除 cookie。它对我有用!

     NSHTTPCookieStorage* cookies = [NSHTTPCookieStorage sharedHTTPCookieStorage];
for (NSHTTPCookie* cookie in
     [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies]) {
    [cookies deleteCookie:cookie];
}
于 2013-07-07T07:06:14.310 回答
0

Nitin 的 Gohel 回答,Swift 版本:

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

您可以使用

    FBSession.setActiveSession(nil)

但是该函数要求一个未包装的对象,因此“nil”似乎不是一个很好的传递参数

于 2015-05-14T13:33:20.313 回答