Search code examples
iosobjective-cfbsdk

Hi I am logging in to facebook and logged out. And when the second time i logged in i need to check Whether the it is a existing user or not?


Methods which I have used:

- (void)  loginButton:(FBSDKLoginButton *)loginButton didCompleteWithResult:(FBSDKLoginManagerLoginResult *)result error:(NSError *)error

- (BOOL) loginButtonWillLogin:(FBSDKLoginButton *)loginButton

- (void)loginButtonDidLogOut:(FBSDKLoginButton *)loginButton

Solution

  • Save FBID in NSuserdefault.

    And On login page compare OLDFBID(stored in NSUserdefaults) with NEWFBID. If both are matched then it is existing user. And not matched then New user. and store new FBID in NSUserdefault.

    Like ,

    // Here posted logic (without syntax) only so, dont copy and paste it. just observe logic.

    When userlogin,
    
    If (nsuserdefault ==nil)
    {
     //store FBID in userdefault
    FBID = (Store here); // 
    }
    else //If value available in nsuserdefault
       {
         if (OLDFBID == NEWFBID)
          {
           // Existing User
          }
         else 
         {
            //New user 
           // Replace new FBID with OLD in NSUserdefault.
         }
    
    }
    

    Note :- Don't clear NSUserdefault at logout.