我正在尝试在我正在开发的iPhone应用程序中编写Facebook集成。我有它登录就好了,但我不喜欢能够打开一个功能而不能关闭它的想法。因此,在处理注销功能时,我遇到了麻烦。
- (IBAction) logoutClicked:(id)sender {
if (fbLoggedIn)
{
FBSession * mySession = [FBSession session];
[mySession logout];
}
}
- (void)sessionDidLogout:(FBSession*)session
{
NSLog(@"Session logged out.");
[theLoginButton setTitle:@"Facebook Time!" forState:UIControlStateNormal];
fbLoggedIn = FALSE;
theLogoutButton.enabled = NO;
theLogoutButton.alpha = 0;
}
logoutClicked方法响应我的xib中的按钮。委托方法没有被调用。我已经尝试将Facebook会话设置为我的ViewController中的属性,以便跨方法存储/访问数据,但这似乎也不起作用。有人有任何解决方案吗?
答案 0 :(得分:0)
sessionDidLogout是在实现FBSessionDelegate的类中实现的吗? 并且它是在使用方法创建会话时作为委托传递的类的实例[FBSession sessionForApplication:@“XXX”secret:@“YYY”delegate:(DELEGATE)]?
答案 1 :(得分:0)
将此代码用于注销。我从link得到了这个。
- (void) fbDidLogout {
NSLog(@"Log out");
// Remove saved authorization information if it exists
if ([userDefaults objectForKey:@"FBAccessTokenKey"]) {
[userDefaults removeObjectForKey:@"FBAccessTokenKey"];
[userDefaults removeObjectForKey:@"FBExpirationDateKey"];
[userDefaults synchronize];
}
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];
}
}
}
答案 2 :(得分:0)
这对我有用:
(void)logout {
//self.sessionDelegate = delegate;
appDelegate.facebook.accessToken = nil;
appDelegate.facebook.expirationDate = nil;
NSHTTPCookieStorage* cookies = [NSHTTPCookieStorage sharedHTTPCookieStorage];
NSArray* facebookCookies = [cookies cookiesForURL:[NSURL URLWithString:@"http://login.facebook.com"]];
for (NSHTTPCookie* cookie in facebookCookies) {
[cookies deleteCookie:cookie];
}
NSLog(@"Log out");
// Remove saved authorization information if it exists
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
if ([userDefaults objectForKey:@"FBAccessTokenKey"]) {
[userDefaults removeObjectForKey:@"FBAccessTokenKey"];
[userDefaults removeObjectForKey:@"FBExpirationDateKey"];
[userDefaults synchronize];
}
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];
}
}
}