简体   繁体   中英

check for already registered with this app in facebook login in ios

I am integrating FB in my app for login & signup purpose in my iOS app..

While i signup with fb from app, i want to know the user has already registered with fb for that app or not,

if he is already registered then i want to perform login actions

otherwise signup actions ..!!

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

    FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
                                  initWithGraphPath:[NSString stringWithFormat:@"/%@",result.token.userID]
                                  parameters:@{ @"fields" : @"id, name, email, first_name, hometown, last_name, location" }
                                  HTTPMethod:@"GET"];
    [request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
        [self handleRequestCompletionWithResult:result error:error];
    }];
}


- (void)handleRequestCompletionWithResult:(id)result error:(NSError *)error
    {
    NSString *title = nil;
    NSString *message = nil;
    if (error) {
        title = @"Graph Request Fail";
        message = [NSString stringWithFormat:@"Graph API request failed with error:\n %@", error];
    } else {
        title = @"Graph Request Success";
        message = [NSString stringWithFormat:@"Graph API request success with result:\n %@", result];
        if(already registered user) {
             //perform login for my app
        } else  {
             //perform signup action for my app
        }
    }
    NSLog(@"%@",message);
}

Is there any way to achieve it?

I did integrate the FBSDK in one of my apps recently, and this is what i did to check if the user is already authorised.

if ([FBSDKAccessToken currentAccessToken]) {
//perform login for your app
}
else {
// perform signup action for your app
}

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM