我在执行使用FBConnct Facebook的整合,它工作正常,但是当我想从Facebook的注销这是行不通的。
我的代码如下:
- (IBAction)logOutbuttonPressed:(id)sender {
[Facebook logout:self];
}
- (void)fbDidLogout {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults removeObjectForKey:@"FBAccessTokenKey"];
[defaults removeObjectForKey:@"FBExpirationDateKey"];
NSLog(@" after %@",facebook.accessToken);
NSLog(@" date%@",facebook.expirationDate);
[defaults synchronize];
}
- (void)logout:(id<FBSessionDelegate>)delegate {
[self logout];
if (delegate != self.sessionDelegate &&
[delegate respondsToSelector:@selector(fbDidLogout)]) {
[delegate fbDidLogout];
}
+(void)fbDidLogout
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if ([defaults objectForKey:@"FBAccessTokenKey"])
{
[defaults removeObjectForKey:@"FBAccessTokenKey"];
[defaults removeObjectForKey:@"FBExpirationDateKey"];
[defaults synchronize];
}
// Hide the publish button.
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];
}
}
}
您需要实现Facebook的注销该代码以及
- (void)fbDidLogout {
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults removeObjectForKey:@"FBAccessTokenKey"];
[defaults removeObjectForKey:@"FBExpirationDateKey"];
NSLog(@" after %@",facebook.accessToken);
NSLog(@" date%@",facebook.expirationDate);
[defaults synchronize];
// Finding the Facebook Cookies and deleting them
NSHTTPCookieStorage* cookies = [NSHTTPCookieStorage sharedHTTPCookieStorage];
NSArray* facebookCookies = [cookies cookiesForURL:
[NSURL URLWithString:@"http://login.facebook.com"]];
for (NSHTTPCookie* cookie in facebookCookies) {
[cookies deleteCookie:cookie];
}
fbGraph = nil;
}
在第二回合视图控制器试试这个进口“FBConnect.h”
然后 .......
FBSession *session = [FBSession session]; [session logout];
调用此方法从Facebook注销。
- (void)logOutFB {
fbGraph.accessToken = nil;
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];
}
}
}