【发布时间】:2012-03-21 11:42:00
【问题描述】:
经过数小时的代码尝试和在线搜索,我不得不寻求帮助。我在 UITableViewCell 中有一个共享按钮。在其触摸操作中,我打开 facebook 登录对话框,然后如果登录,我会显示提要对话框。它工作正常,但即使我通过 Facebook 应用程序注销 sessionIsValid 显示是。这是代码...
if(indexPath.row==0)
{
AppId=@"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];
}
【问题讨论】:
标签: iphone facebook session fbconnect