Akash Malhotra
Akash Malhotra

Reputation: 1106

iPhone facebook sdk shows Valid session even when I logged out through Facebook app

After many hours of trying codes, searching online, I have to ask for help. I have a share button in a UITableViewCell. On its touch action I open facebook login dialog and then if logged in I show feed dialog. It working fine but even if I logout through Facebook app the sessionIsValid shows YES. Here's the Code...

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];

}

Upvotes: 0

Views: 313

Answers (1)

Nick Bull
Nick Bull

Reputation: 4286

That's correct. Each app has it's own sandboxed area. So you have authorised your app and your app has stored a token that it can use for validating itself. It knows nothing about any other app. So if you logout in the facebook app, it doesn't know.

Upvotes: 1

Related Questions