在Facebook-Ios-Sdk关闭Facebook会话

Chr*_*ien 11 iphone facebook facebook-graph-api ios

如何关闭aCtive Session 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];

                                 }];


                            }];    } 


 }
Run Code Online (Sandbox Code Playgroud)

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


}
Run Code Online (Sandbox Code Playgroud)

Nit*_*hel 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];
Run Code Online (Sandbox Code Playgroud)

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

Facebook图形api注销不工作

Facebook iOS SDK 3.1.1"closeAndClearTokenInformation"方法无效

希望它能帮助你