4

I have implemented Facebook login and checking the status of my access token in

-(void)fbDidLogin

Now, I have a UITableView where I have a toggle Button as UISwitch which turns on if I have got an access token. The problem is, when I get an access token

-(void)fbDidLogin 

method gets called. Here, I'm setting the switch of toggle button on by calling

[self.switch setOn:YES animated:YES];

but its not happening. when I go back and open that page again, its showing the right status but not when I set it in fbDidLogin. Any guesses why this is happening?

For facebook authentication, it goes outside of the application and comes back, maybe thats why its happening? but I'm calling a webservice from fbDidLogin and its working fine.

code is simple

- (void)fbDidLogin {    
    [self.switch setOn:YES animated:YES];    
}
Adil Soomro
  • 37,609
  • 9
  • 103
  • 153
nachiket talwalkar
  • 197
  • 1
  • 1
  • 6
  • maintain flag in appdelegate when facebook login or logout and now add code in view will appear method if flag true switch is on and vice-versa – Paresh Navadiya May 21 '12 at 11:38
  • None of Viewdidload,Viewwillappear and viewdidappear of that controller gets called when it returns after authenticating. It only comes in fbdidLogin. – nachiket talwalkar May 21 '12 at 11:42
  • maintain flag in appdelegate when facebook login or logout. Now in - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *) method if flag true switch is on and vice-versa – Paresh Navadiya May 21 '12 at 11:51
  • Yup did that, thats the problem. Its not going in CellForRowAtIndexPath. I set a breakpoint there, but when application enters foreground, it just does not go to that method. – nachiket talwalkar May 21 '12 at 11:54
  • Post notification method when application enters foreground it will have logic [tableview reloadData]; – Paresh Navadiya May 21 '12 at 11:58
  • refer to [this](http://stackoverflow.com/questions/6810105/giving-notification-to-another-class-with-nsnotificationcenter) link for notification – Paresh Navadiya May 21 '12 at 12:01
  • Its still not working for me.Thanks for the help. I'll post here if I find an answer.Any further help would be much appreciated.. Thanks. – nachiket talwalkar May 21 '12 at 12:34

1 Answers1

1

where u get access token for fb add post notification

[[NSNotificationCenter defaultCenter] postNotificationName:@"fbDidLogin" object:nil];

Now the method for intial fb login is

-(void)fbLogin
{
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(fbDidLogin) name:@"fbDidLogin" object:nil];
 // some logic for intial fb login page
 }

Also in fbDidLogin method add this

- (void)fbDidLogin 
{   
[[NSNotificationCenter defaultCenter]removeObserver:self name:@"fbDidLogin" object:nil]; 
[self.switch setOn:YES animated:YES];    
}

Here fbDIdLogin will be called as soon as access token is recieved

Similar process can be done for fb login failed if access token is nil .

Paresh Navadiya
  • 38,095
  • 11
  • 81
  • 132