简体   繁体   中英

Logout from Facebook after a share with Facebook iOS SDK

I'm building an iPad app where the user can post an image to his/her timeline. These iPads are rentable, so the user should be logged out after the share has been done.

I've implemented the iOS Facebook Login, so the user is redirected to Safari to login. After the share I clean up all the tokens and within my app the session is destroyed, but when I go to Safari afterwards the user is still logged in.

Is there a way to make sure the user is logged out everywhere?

Kind regards, Frederik

I've done something similar in the past. It was a flow where any user holding the iPad logs in with his or hers FB credentials, forcing the sdk to present a webview.

A quick look, this is the code I wrote for it: (this code is 1.5y old)

 FBSession *newSession = [[FBSession alloc] initWithPermissions:@[
                             @"user_about_me",
                             @"publish_actions",
                             @"user_birthday",
                             @"friends_birthday",
                             @"email"
                            ]];


    [FBSession setActiveSession:newSession];

    [[FBSession activeSession] openWithBehavior:FBSessionLoginBehaviorForcingWebView completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {

        [FBSession setActiveSession:session];

        if(error){
            NSLog(@"Error opening session");
            [self showLoginError:error];
            return;
        }

        if(status == FBSessionStateOpen){
            NSLog(@"FB session opened");
            [self getMe];
        }
    }];

When the flow ends, or the user cancels the flow, I logs the user out as follows:

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

UPDATE: The code for the share dialog:

NSMutableDictionary *dialogParameters = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                   [NSString stringWithFormat:@"%@ - Vote for us!", 
                                   teamName, @"name",
                                   @"Campaign title", @"caption",
                                   shareMessage, @"description",
                                   shareTeamPageURL, @"link",
                                   sharePictureURL, @"picture", nil];


    [FBWebDialogs presentFeedDialogModallyWithSession:[FBSession activeSession] 
    parameters:dialogParameters 
    handler:nil];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM