iOS - Facebook Connect 注销不会删除登录详细信息? [英] iOS - Facebook Connect logout not deleting login details?

查看:23
本文介绍了iOS - Facebook Connect 注销不会删除登录详细信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在另一个项目中使用了 Facebook Connect,但问题相对较少,但是在我当前的项目中,当我调用 [facebook logout]; 时,它似乎没有删除用户详细信息.如果我然后重新启动应用程序,我在 didFinishLaunchingWithOptions 函数中有以下内容:

I have used Facebook Connect on another project with relatively few problems, however on my current project it seems that when I call [facebook logout]; it doesn't remove the users details. If I then restart the app, I have the following in the didFinishLaunchingWithOptions function:

facebook = [[Facebook alloc] initWithAppId:@"XXXXXXXXXXXXX" andDelegate:self];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

if([defaults objectForKey:@"FBAccessTokenKey"]
   && [defaults objectForKey:@"FBExpirationDateKey"]){
    facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"];
    facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"];

}

    NSLog(@"startup login");
    [self loginToFacebook];//attempt to login automatically on startup

我的 loginToFacebook 函数是这样的:

My loginToFacebook function is this:

- (void)loginToFacebook
{
    NSLog(@"Logging into facebook");
    //set up facebook and login in automatically if possible
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

    if([defaults objectForKey:@"FBAccessTokenKey"]
       && [defaults objectForKey:@"FBExpirationDateKey"]){
        facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"];
        facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"];

    }

    if (![facebook isSessionValid]){

        //get permissions that user will need to agree to us using
        NSArray *permissions = [[NSArray alloc] initWithObjects:
                                @"user_likes",@"read_friendlists",@"offline_access", @"publish_stream",
                            nil];
        //authorise our login
        [facebook authorize:permissions];
        [permissions release];
    }
    else
    {
        [facebook authorize:nil];
    }
}

就我而言,这次应该提示我使用我的电子邮件和密码登录.我主要使用模拟器,所以 Facebook 应用程序本身不是原因,在 Facebook.h 类中我已经改变了

As far as I am concerned, this time I should be prompted to login with my email and password. I am mostly using the simulator so the Facebook app itself is not the cause, and in the Facebook.h class I have changed

[self authorizeWithFBAppAuth:NO safariAuth:YES];

[self authorizeWithFBAppAuth:NO safariAuth:NO];

然而,facebook 窗口会短暂闪烁并消失,正如我在我已经登录时所期望的那样.然后它从我以前的登录详细信息中加载我的 ID、姓名、朋友列表等.我不能再更换用户了!我应该补充一点,我有以下代码,在注销"时相应地打印:

However what happens is that the facebook window briefly flashes up and disappears, as I would expect it to when I am already logged in. It then loads my id, name, friends list etc from my previous login details. It's no longer possible for me to change users! I should add that I have the following code which prints accordingly on 'logout':

- (void)fbDidLogout{
    NSLog(@"Logged out of facebook");
}

...在调用 [facebook logout] 时打印到控制台.我也有正确的 url 方案,所以那里没有问题.

...which prints to the console when [facebook logout] is called. I also have the correct url schemes in place so there is no problem there.

正如我所说,我已经在另一个应用程序上使用了它,但这次我看不出我可以忽略什么.我欢迎任何建议,因为我怀疑这是非常简单的事情.

As I say I've got this working on another app, but I can't see what I could've overlooked this time. I welcome any suggestion, as I suspect it's something ridiculously simple.

我刚刚在设备上对其进行了测试,尝试登录 Facebook 导致应用崩溃.我怀疑这是因为它试图使用存储"信息登录,而该信息不存在,因为我还没有登录设备.我仍在调查中,但如果有人能看到明显的缺陷,我将不胜感激.

I've just tested it out on a device, and the attempt to login to Facebook causes the app to crash. I suspect it's because it's attempting to login using 'stored' info, which doesn't exist because I haven't logged in on the device yet. I'm still investigating but again, if any can see an obvious flaw I'd be very grateful.

Edit2:我尝试使用保险箱的示例删除 cookie.我还在 a) didFinishLaunchingWithOptions 和 b) 在 fbDidLogout 期间打印出所有 cookie,我得到以下信息:

I've tried removing cookies using safecase's example. I also print out all of the cookies during a) didFinishLaunchingWithOptions and b) during fbDidLogout, and I get the following:

a)`2012-05-18 10:40:40.665 MyApp[15545:17003] ("",

a) `2012-05-18 10:40:40.665 MyApp[15545:17003] ( "",

"<NSHTTPCookie version:0 name:"c_user" value:"634361620" expiresDate:2012-06-17 09:34:33 +0000 created:2012-05-18 09:34:34 +0000 (3.59026e+08) sessionOnly:FALSE domain:".facebook.com" path:"/" isSecure:TRUE>",
"<NSHTTPCookie version:0 name:"csm" value:"2" expiresDate:2012-06-17 09:34:33 +0000 created:2012-05-18 09:34:34 +0000 (3.59026e+08) sessionOnly:FALSE domain:".facebook.com" path:"/" isSecure:FALSE>",
"<NSHTTPCookie version:0 name:"datr" value:"gxe2T8ZyBzMGb5w3LS29Q0kJ" expiresDate:2014-05-18 09:34:33 +0000 created:2012-05-18 09:34:34 +0000 (3.59026e+08) sessionOnly:FALSE domain:".facebook.com" path:"/" isSecure:FALSE>",
"<NSHTTPCookie version:0 name:"locale" value:"en_US" expiresDate:2012-05-25 09:36:43 +0000 created:2012-05-18 09:36:44 +0000 (3.59027e+08) sessionOnly:FALSE domain:".facebook.com" path:"/" isSecure:FALSE>",
"<NSHTTPCookie version:0 name:"lu" value:"RgayA7CMIlsAl-lOD2-Y-O3g" expiresDate:2014-05-18 09:34:33 +0000 created:2012-05-18 09:34:34 +0000 (3.59026e+08) sessionOnly:FALSE domain:".facebook.com" path:"/" isSecure:FALSE>",
"<NSHTTPCookie version:0 name:"m_user" value:"0%3A0%3A0%3A0%3Av_1%2Cajax_1%2Cwidth_320%2Cpxr_1%2Cgps_1%3A1337333673%3A2" expiresDate:2012-08-16 09:34:33 +0000 created:2012-05-18 09:34:34 +0000 (3.59026e+08) sessionOnly:FALSE domain:".facebook.com" path:"/" isSecure:FALSE>",
"<NSHTTPCookie version:0 name:"s" value:"Aa4WdKU-oOFathmK" expiresDate:2012-06-17 09:34:33 +0000 created:2012-05-18 09:34:34 +0000 (3.59026e+08) sessionOnly:FALSE domain:".facebook.com" path:"/" isSecure:TRUE>",
"<NSHTTPCookie version:0 name:"xs" value:"125%3AFFIWXjAXDXUMmw%3A2%3A1337333673" expiresDate:2012-06-17 09:34:33 +0000 created:2012-05-18 09:34:34 +0000 (3.59026e+08) sessionOnly:FALSE domain:".facebook.com" path:"/" isSecure:TRUE>"

)`

b)2012-05-18 10:41:16.530 MyApp[15545:17003] ()

由于它变为空,我认为它们已被删除.但是在重新打开应用程序时,它们又都出现了.

Since it changes to empty, I would assume they are deleted. But on reopening the app, they are all there again.

Edit3:我发现解决此问题的唯一方法是在应用程序打开后立即删除所有 cookie,但这意味着用户每次都必须登录,即使他们上次使用该应用程序时仍保持登录状态打开.目前这是一个临时修复,我仍然不确定为什么它不能正常工作.

The only way around this I have found is to delete all cookies as soon as the application opens, however this means the user has to login every time, even if they left themselves logged in the last time they had the app open. It's a temporary fix for the moment, I'm still not sure why it's not working as it should be.

推荐答案

当用户单击注销并删除存储在 userdefault for facebook 的所有密钥时,您提供此方法

You provide this method when user clicks on logout and remove all keys stored in userdefault for facebook

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

这篇关于iOS - Facebook Connect 注销不会删除登录详细信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆