OGeek|极客世界-中国程序员成长平台

标题: iphone - 在一台设备上为多个用户在 iOS 应用程序中登录 Facebook [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 14:38
标题: iphone - 在一台设备上为多个用户在 iOS 应用程序中登录 Facebook

我的应用将被多个用户使用。

如何以某种方式集成 facebook,以便 safari 不会保存任何用户凭据并在每次有人尝试登录时抛出登录页面。

我已经使用 FBSessionLoginBehaviorForcingWebView 来强制在应用程序内进行 Web View 登录,但问题是,当第一个用户尝试通过应用程序中显示的 View 登录到 fb 时,控件然后转到 safari 进行身份验证,它只是保存信用。

因此,当其他用户尝试登录并在应用程序本地 UIWebView 中输入他的凭据时,控件会再次转到 safari,它已经存储了 previos creds 并且新用户无法进行身份验证。

所以基本上第一个用户是永久登录的。清除 WebView 的 cookie 不起作用。我无法清除它们以进行 safari。

帮助 提前致谢。

这就是我一直在做的事情

if([FBSession activeSession].isOpen)
{
   [[FBSession activeSession] closeAndClearTokenInformation];//Also, clearing all the local cookies
}
else
{
  AppDelegate *delegate = [UIApplication sharedApplication].delegate;
  delegate.session = [[FBSession alloc] init];
  [FBSession setActiveSession:delegate.session];
  [delegate.session openWithBehavior:FBSessionLoginBehaviorForcingWebView    completionHandler:^(FBSession *session1, FBSessionState status, NSError *error) {
    if (!error) {
       [self openSession]; // your method
    }
   }];
 }


- (void)sessionStateChangedFBSession *)session stateFBSessionState) state errorNSError *)error{
switch (state) {
    case FBSessionStateOpen:
    {
        [FBRequestConnection startForPostStatusUpdate"Some message"completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
            if (!error) {

                //logout again
                NSLog(@"startForPostStatusUpdate SUCESS");
            }
            else {
                //logout again
                NSLog(@"startForPostStatusUpdate FAIL");
            }
        }];

    }
        break;
    case FBSessionStateClosed:
    {
        NSLog(@"FBSessionStateClosed");
    }
        break;
    case FBSessionStateClosedLoginFailed:
        [FBSession.activeSession closeAndClearTokenInformation];
        break;
    default:
        break;
}
if (error) {
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle"Error" message:error.localizedDescription delegate:nil cancelButtonTitle"OK" otherButtonTitles:nil];
    [alertView show];
}
}

另外,使用您的方法修改了应用委托(delegate)。



Best Answer-推荐答案


找到了解决办法。基本上,调用以下内容:

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

仅清除本地 FB session 信息,但不清除 Safari cookie。因此,在我登录用户后,我清除了 Safari cookie:

NSHTTPCookie *cookie;
NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
for (cookie in [storage cookies]) {
    [storage deleteCookie:cookie];
}
[[NSUserDefaults standardUserDefaults] synchronize];

它不是很优雅,但很有效。现在,当下一个用户尝试登录时,它会强制他们输入凭据。

关于iphone - 在一台设备上为多个用户在 iOS 应用程序中登录 Facebook,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18827195/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4