0

i work with NSNotification and unfortunately i can not debug the selector. In my ViewController.m, in the viewdidload method i implement the NSNotifiaction call. Also in my ViewController.m I implement the selector. Unfortunately i can not debug the selector. Here is my code:

//Observe for the custom Notification regarding the session state change
[[NSNotificationCenter defaultCenter] addObserver:self
                                      selector:@selector(handleFBSessionStateChangeWithNotification:)
                                      name:@"SessionStateChangeNotification"
                                      object:nil];


- (void)handleFBSessionStateChangeWithNotification:(NSNotification*)notififcation
{
    //Get the session, state and error values from the notification`s userinfo dictionary
    NSDictionary* userInfo = [notififcation userInfo];

    FBSessionState sessionState = [[userInfo objectForKey:@"state"]integerValue];
    NSError* error = [userInfo objectForKey:@"error"];

    //Handle the session state
    //The interesting states are the opened session, the closed session and the failed loggin
    if(!error) {
        //In Case not error, then check if the session is opened or closed
        if (sessionState==FBSessionStateOpen) {
            [FBRequestConnection startWithGraphPath:@"me"
                                         parameters:@{@"fields":@"first_name,last_name,email"}
                                         HTTPMethod:@"Get"
                                  completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
                                      if (!error) {
                                          NSLog(@"result : %@",result);
                                      }
                                      else{
                                          NSLog(@"%@",[error localizedDescription]);
                                      }
                                  }];
        }

        else if (sessionState==FBSessionStateClosed||sessionState==FBSessionStateClosedLoginFailed)  {
            //A session was closed or the login was failed. Update the UI accordingly
            NSLog(@"the session is closed");
        }
    }
    else {
        //In case an error has occured
        NSLog(@"Error: %@",[error localizedDescription]);
    }
}
jww
  • 97,681
  • 90
  • 411
  • 885
Fahem Issameddine
  • 293
  • 1
  • 2
  • 10
  • Where is the `SessionStateChangeNotification` being posted from? Are you sure it is, and with that name? – Wain Mar 02 '15 at 12:21
  • from the appDelegate: – Fahem Issameddine Mar 02 '15 at 12:29
  • The name should be as it is to use `postNotification`, please confirm that, then there is no why that this notification is not being called unless the view is already `nil`. – Syed Ali Salman Mar 02 '15 at 12:34
  • Ok i will try. In the Appdelegate i wrote //Create a new notification, add the sessionStateInfo dictionary to it and post it. [[NSNotificationCenter defaultCenter] postNotificationName:@"SessionStateChangeWithNotification" object:nil userInfo:sessionSateInfo]; – Fahem Issameddine Mar 02 '15 at 12:39
  • SessionStateChangeWithNotification != SessionStateChangeNotification – Peter Segerblom Mar 02 '15 at 12:40
  • Peter: That was the mistake. I `m so stupid. Thank you SyedAliSalman and Peter Segerblom – Fahem Issameddine Mar 02 '15 at 12:43
  • It is good practice to use constants for your `NSNotification` names, to avoid this issue. It will save you lots of pain, as XCode will autocomplete the constant for you and warn you if have a typo. – dmorrow Mar 02 '15 at 12:58
  • It is good practice to use constants for your `NSNotification` names, to avoid this issue. It will save you lots of pain, as XCode will autocomplete the constant for you and warn you if have a typo. `extern NSString *const kSessionStateChangeNotification;` in the .h and `NSString *const kSessionStateChangeNotification = @"kSessionStateChangeNotification";` in the .m – dmorrow Mar 02 '15 at 12:58
  • dmorrow: Yes you have right. I will implement it like you note – Fahem Issameddine Mar 02 '15 at 14:48

0 Answers0