2

我正在我的应用程序中集成 FB,以便在我的 iOS 应用程序中登录和注册。

当我从应用程序注册 fb 时,我想知道用户是否拥有already registered with fb该应用程序,

如果他已经注册了,那么我想表演login actions

否则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);
}

有没有办法实现它?

4

1 回答 1

0

我最近确实在我的一个应用程序中集成了 FBSDK,这就是我检查用户是否已获得授权的方法。

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

希望这可以帮助。

于 2016-02-09T10:10:30.550 回答