0
オンラインで検索すると何時間ものコードを試した後、私は助けを求める必要があります。私はUITableViewCellに共有ボタンを持っています。そのタッチアクションで私はFacebookのログインダイアログを開き、ログインしていればフィードダイアログを表示します。それは正常に動作しますが、私がFacebookのアプリケーションを介してログアウトしても、sessionIsValidはYESを示します。コードは次のとおりです。iPhone facebook sdkは、Facebookアプリからログアウトしても有効なセッションを表示します。
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と有効期限の値を削除していたので、他の解決策は考えられません。何か案は? –