0
經過許多小時的代碼嘗試,在線搜索後,我必須尋求幫助。我在UITableViewCell中有一個共享按鈕。在其觸摸動作上,我打開Facebook登錄對話框,然後如果登錄,我會顯示提要對話框。它工作正常,但即使我通過Facebook應用程序註銷sessionIsValid顯示YES。這裏的代碼...即使當我通過Facebook應用程序註銷時,iPhone facebook sdk也會顯示有效會話
if(indexPath.row==0)
{
[email protected]"xxx";
AppDelegate *appDelegate=(AppDelegate*)[[UIApplication sharedApplication]delegate];
appDelegate.scheduleViewController=self;
self.facebook = [[Facebook alloc] initWithAppId:AppId andDelegate:self];
// [self.facebook requestWithGraphPath:@"me" andDelegate:self];
if ([defaults objectForKey:@"FBAccessTokenKey"]
&& [defaults objectForKey:@"FBExpirationDateKey"]) {
self.facebook.accessToken = [defaults objectForKey:@"FBAccessTokenKey"];
self.facebook.expirationDate = [defaults objectForKey:@"FBExpirationDateKey"];
}
if (![self.facebook isSessionValid]) {
[self.facebook authorize:permissions];
}
else
[self doStuffAfterLogin:[self.facebook accessToken]];
}
- (void)fbDidLogin {
[defaults setObject:[self.facebook accessToken] forKey:@"FBAccessTokenKey"];
[defaults setObject:[self.facebook expirationDate] forKey:@"FBExpirationDateKey"];
[defaults synchronize];
[self doStuffAfterLogin:[self.facebook accessToken]];
}
- (void)request:(FBRequest *)request didFailWithError:(NSError *)error {
NSLog(@"%@", [error localizedDescription]);
NSLog(@"Err details: %@", [error description]);
UIAlertView *alertView=[[UIAlertView alloc]initWithTitle:@"Error!" message:@"Error!" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alertView show];
[defaults removeObjectForKey:@"FBAccessTokenKey"];
[defaults removeObjectForKey:@"FBExpirationDateKey"];
[self.facebook authorize:permissions];
}
-(void)doStuffAfterLogin:(NSString*)accessToken;
{
NSMutableString *imgUrl=[[NSMutableString alloc]init];
if([[defaults objectForKey:@"imageUrl"] isEqualToString:@""])
imgUrl= @"http://artist.eventseekr.com/images/no-photo.png";
else
imgUrl=[defaults objectForKey:@"imageUrl"];
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
AppId, @"app_id",
imgUrl, @"picture",
[NSString stringWithFormat:@"Watch %@ in action at the %@ event",[defaults objectForKey:@"name"],[defaults objectForKey:@"eventName"]], @"caption",
@"Sample Festival App", @"description",
nil];
[self.facebook dialog:@"feed" andParams:params andDelegate:self];
}
因此,我做的是在應用程序啓動時刪除NSUserdefaults中的accessToken和過期值,我不能想到任何其他解決方案。有任何想法嗎? – 2012-03-21 12:15:36