1

我已经使用 Facebook SDK 注销了 facebook。但是,再次转到同一帐户,它在表格视图中显示值两次(例如:Prem Kumar。此名称在单元格中显示两次)。

//用于登录

- (void)loginViewShowingLoggedInUser:(FBLoginView *)loginView

{
    // first get the buttons set for login mode


       NSLog(@"success");


    [HUD showWhileExecuting:@selector(LoadingProcess) onTarget:self withObject:nil animated:YES];

    if (FBSession.activeSession.isOpen)
    {

       NSLog(@"TOKEN : %@",[[FBSession activeSession]accessTokenData]);

        FBRequest *friendRequest = [FBRequest requestForGraphPath:@"me/friends?fields=name,picture,birthday,location"];

        [friendRequest startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error)
        {
            NSArray *data = [result objectForKey:@"data"];
            for (FBGraphObject<FBGraphUser> *friend in data)
            {
                [delegate.friendsListArray addObject:friend];
                NSLog(@"%@:%@:%@", [friend name],[friend birthday],[friend id]);
            }

             if ([delegate.friendsListArray count]!=0)

             {


            NSUserDefaults * standardDefaults=[NSUserDefaults standardUserDefaults];
            [[NSUserDefaults standardUserDefaults] synchronize];

            [standardDefaults setObject:delegate.friendsListArray forKey:@"FriendsListArray"];
            [standardDefaults setBool:YES forKey:@"logged_in"];
            [standardDefaults synchronize];


            NSLog(@"%@",[standardDefaults objectForKey:@"FriendsListArray"]);

            BirthdayList * birthdaylist=[[BirthdayList alloc]init];
            [self.navigationController pushViewController:birthdaylist animated:NO];
            [birthdaylist release];
              }
            else
            {
                UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Friends not found" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
                [alertView show];
                [alertView release];
            }
        }];

    }

}

在设置.m

-(void)LogoutTapped
{


    NSLog(@"Logged out of facebook");

    NSUserDefaults * standardDefaults=[NSUserDefaults standardUserDefaults];
    [[NSUserDefaults standardUserDefaults] synchronize];

    NSArray *keys = [[[[NSUserDefaults standardUserDefaults] dictionaryRepresentation]allKeys]copy];

       for(NSString *key in keys)
    {
        [standardDefaults removeObjectForKey:key];
        [standardDefaults removeObjectForKey:@"FriendsListArray"];
        [standardDefaults removeObjectForKey:@"logged_in"];
        [standardDefaults synchronize];

        NSLog(@"Key Name: %@", key);

    }

    [delegate.friendsListArray removeAllObjects];
    [keys release];

    NSLog(@"%@",[standardDefaults objectForKey:@"FriendsListArray"]);

    NSLog(@"%@",[standardDefaults objectForKey:@"logged_in"]);


    NSUserDefaults * userinfodefaults=[NSUserDefaults standardUserDefaults];
    NSArray *userkeys = [[[[NSUserDefaults standardUserDefaults] dictionaryRepresentation]allKeys]copy];

    for(NSString *userkey in userkeys)
    {
        [userinfodefaults removeObjectForKey:userkey];
        [userinfodefaults removeObjectForKey:@"userinfo"];
        [userinfodefaults removeObjectForKey:@"userbool"];

        NSLog(@"key1 Name: %@",userkey);
    }

    [delegate.UserListArray removeAllObjects];
    [delegate.Setmonthdataarray removeAllObjects];
    [delegate.SetMonthlistarray removeAllObjects];
    [userinfodefaults synchronize];
    [userkeys release];


    FBSession *session=[FBSession activeSession];
    [session closeAndClearTokenInformation];
    [session close];
    [[FBSession activeSession] closeAndClearTokenInformation];
    [[FBSession activeSession] close];
    [FBSession setActiveSession:nil];

    [delegate facebook].accessToken=nil;
    [delegate facebook].expirationDate=nil;

    NSHTTPCookieStorage* cookies = [NSHTTPCookieStorage sharedHTTPCookieStorage];
    NSArray* facebookCookies = [cookies cookiesForURL:
                                [NSURL URLWithString:@"http://login.facebook.com"]];
    for (NSHTTPCookie* cookie in facebookCookies)
    {
        [cookies deleteCookie:cookie];
    }

    for (NSHTTPCookie *_cookie in cookies.cookies)
    {
        NSRange domainRange = [[_cookie domain] rangeOfString:@"facebook"];
        if(domainRange.length > 0){
            [cookies deleteCookie:_cookie];
        }
    }


    UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Logout" message:@"Logout Successfully" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alert show];
    [alert release];

    MainList * mainlist=[[MainList alloc]initWithNibName:@"MainList" bundle:nil];

    [self.navigationController pushViewController:mainlist animated:NO];

    [mainlist release];

}

还有一个疑问。

要登录 facebook,我使用了 Facebook SDK。

要注销 facebook,我使用了 Facebook 库。(Facebook.m,Facebook.h)

有什么问题吗?

任何想法请帮助我。

4

1 回答 1

5

以下代码可能对您有所帮助:

-(void) fbDidLogout
    {
        NSLog(@"Logged out of facebook");
        NSHTTPCookie *cookie;
        NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
        for (cookie in [storage cookies])
        {
            NSString* domainName = [cookie domain];
            NSRange domainRange = [domainName rangeOfString:@"facebook"];
            if(domainRange.length > 0)
            {
                [storage deleteCookie:cookie];
            }
        }
    }//

从您的上下文来看,我假设您的设备没有安装 Facebook 应用程序,您也不希望使用 iOS 6 系统身份验证,这将保留默认登录行为以使用 Safari。如果您要清除 Safari cookie,那应该可以工作,但为了在您的场景中获得更流畅的体验,您应该使用该FBSession openWithBehavior:completionHandler:方法并指定一个行为,FBSessionLoginBehaviorForcingWebview以便它使用内联 webview 对话框进行身份验证。

有关示例,请参阅 Facebook iOS SDK 中的 SwitchUserSample,因为该示例演示了一个可以在多个帐户之间切换的应用程序。

https://developers.facebook.com/docs/ios/login/#logout

https://developers.facebook.com/docs/ios/ios-sdk-tutorial/

于 2013-08-29T04:22:11.997 回答