我在我的应用程序中集成了facebook,允许用户使用facebook登录或使用我的Facebook应用程序发布评论。但问题是用户首次登录后,始终会被记录,并且每次评论或登录时都不会提示用户登录,甚至会调用[facebook logout]。我在Feed之前或之后尝试过删除cookie:
-(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];
}
} }//End of Method
,但是,它给出了“找不到页面”错误“。这是我的代码:
-(void) facebookPost{
if (facebook==nil)
facebook = [[Facebook alloc] initWithAppId:kAppId andDelegate:self];
NSString *path= [NSString stringWithFormat:@"%@%@",imageService,self.newsDetail.image];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
if ([defaults objectForKey:@"FBAccessTokenKey"]
&& [defaults objectForKey:@"FBExpirationDateKey"]) {
facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"];
facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"];
}
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
kAppId, @"app_id",
path, @"picture",
self.titulo.text, @"name",
self.texto.text, @"caption",
self.newsDetail.link, @"link",
nil];
[facebook dialog:@"feed" andParams:params andDelegate:self];
kAppId=nil;
imageService=nil;
path=nil;
defaults=nil;
params=nil;
}
- (void)dialogDidComplete:(FBDialog *)dialog:(FBDialog *)dialog{
[facebook logout];
}
登录时会出现同样的问题,首次登录后,系统不会提示用户登录,而是直接登录应用程序。
非常感谢。