gpt4 book ai didi

iphone - 在 Facebook-Ios-Sdk 中关闭 Facebook session

转载 作者:技术小花猫 更新时间:2023-10-29 10:42:23 25 4
gpt4 key购买 nike

每次启动我的应用程序时,我如何关闭 Facebook-iOS-Sdk 的事件 session ,或者在终止应用程序后它会给我之前的登录 session 详细信息。当我点击 facebook 按钮时。我已经使用了所有东西 [appDelegate.session closeAndClearTokenInformation]; [FBSession.activeSession close]; [FBSession.activeSession closeAndClearTokenInformation] ..但事件 session 仍未关闭..如何在单击时关闭上一个 session 数据。

我使用下面的代码来清除,但每当我点击 facebook 按钮开始新 session 时..它会返回我之前的凭据。

- (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];
}


}

最佳答案

嗨,Christien 可能会在下方提供两个链接,这对您有帮助,请刷新 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 log out not working

Facebook iOS SDK 3.1.1 "closeAndClearTokenInformation" method no working

希望对你有帮助

关于iphone - 在 Facebook-Ios-Sdk 中关闭 Facebook session ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14432808/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com