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

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

问题描述

我在另一个项目中使用了Facebook Connect,但是在我目前的项目中,当我打电话给 [facebook logout]; 它不会删除用户详细信息。如果我重新启动应用程序,我在didFinishLaunchingWithOptions函数中有以下内容:

  facebook = [[Facebook alloc] initWithAppId:@ XXXXXXXXXXXXXandDelegate:self]; 
NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];

如果([defaults objectForKey:@FBAccessTokenKey]
&&&& @ FBAccessTokenKey];
facebook.expirationDate = [defaults objectForKey:@FBExpirationDateKey];

}

NSLog(@启动登录);
[self loginToFacebook]; //尝试在启动时自动登录

我的loginToFacebook功能是这个:

   - (void)loginToFacebook 
{
NSLog(@登录到Facebook);
//设置Facebook并自动登录
NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];

如果([defaults objectForKey:@FBAccessTokenKey]
&&&& @ FBAccessTokenKey];
facebook.expirationDate = [defaults objectForKey:@FBExpirationDateKey];

}

if(![facebook isSessionValid]){

//获取用户需要同意我们使用$ b $的权限b NSArray * permissions = [[NSArray alloc] initWithObjects:
@user_likes,@read_friendlists,@offline_access,@publish_stream,
nil];
//授权我们的登录
[facebook authorize:permissions];
[权限释放];
}
else
{
[facebook authorize:nil];
}
}

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

  [self authorizeWithFBAppAuth:NO safariAuth:YES]; 

  [self authorizeWithFBAppAuth:NO safariAuth:NO]; 

然而,发生什么事情是,Facebook窗口短暂地闪烁并消失,正如我预期的那样我已经登录,然后从我以前的登录详细信息中加载我的id,name,friends列表等。我不可能改变用户!我应该补充说,我有以下代码相应地在'logout'上打印:

   - (void)fbDidLogout {
NSLog(@登出Facebook);
}

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



正如我所说,我已经在另一个应用程序上工作,但我看不到我这次可以忽略什么
我欢迎任何建议,因为我怀疑这是一个荒谬的简单。



编辑:我刚刚在设备上测试过,尝试登录到Facebook会导致应用崩溃。我怀疑是因为它尝试使用存储信息进行登录,该信息不存在,因为我尚未登录设备。我仍然在调查,但再次,如果有什么可以看到一个明显的缺陷,我将非常感激。



Edit2:我尝试使用safecase的例子删除cookies。我也打印出所有的cookies,在a)didFinishLaunchingWithOptions和b)在fbDidLogout期间,我得到以下内容:



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

 < NSHTTPCookie版本: 0名称:\c_user\值:\634361620\expiresDate:2012-06-17 09:34:33 +0000创建时间: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:\Aa4WdK U-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>

)` / p>

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



由于它变为空,我假设它们被删除。但是在重新打开应用程序时,他们都会重新开放。



编辑3:我发现的唯一方法是在应用程序打开后立即删除所有的Cookie这意味着用户必须每次登录,即使他们在上次打开应用程序时离开自己登录。这是一个暂时的修复,我仍然不知道为什么它不工作,因为它应该是。

解决方案

你提供这种方法当用户点击退出并删除存储在userdefault中的所有键为Facebook

   - (void)fbDidLogout 
{
NSLog(@Log out out 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];
}
}
}


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

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

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

to

[self authorizeWithFBAppAuth:NO safariAuth:NO];

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");
}

...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.

Edit: 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: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] ( "",

"<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: 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.

解决方案

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天全站免登陆