gpt4 book ai didi

ios - 检查 Facebook 帐户是否链接到 PFUser

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:38:49 25 4
gpt4 key购买 nike

在 Parse 文档中,它说您可以检查用户是否链接到 Facebook 帐户,但是有什么方法可以反之亦然吗?例如,假设用户单击一个按钮以使用 Facebook 登录,因为 [PFUser currentUser] 为 nil(因为用户尚未登录),Parse 将为该用户创建一个新帐户因为您不能使用 [PFFacebookUtils isLinkedWithUser: [PFUser currentUser]]。似乎链接帐户的唯一方法是在用户定期登录后(即输入用户名和密码),但这确实很不方便。如果用户已经手动创建了一个帐户(通过填写我提供的注册表)然后决定链接他们的 Facebook 帐户怎么办?那么,有没有办法检查 Facebook 帐户是否与一般用户相关联,而不是针对特定用户进行检查?

最佳答案

好的,这是解决方案。基本上遍历每个用户,看看 Facebook 帐户是否与该帐户相关联。在此基础上,链接或创建一个新帐户。这是代码:

PFQuery *userQuery = [PFUser query];
[userQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
NSUInteger count = [objects count];
BOOL linked = NO;
for(NSUInteger i = 0; i < count; i++){

PFUser *checkUser = objects[i];
if([PFFacebookUtils isLinkedWithUser:checkUser]){
linked = YES;
NSLog(@"profile is linked to a user");
break;

}
}
if(linked == YES){
[PFFacebookUtils logInWithPermissions:_permissions block:^(PFUser *user, NSError *error) {
if(!user){
NSLog(@"facebook cancelled");


}
else{

_type = @"twitter";
[self performSegueWithIdentifier:@"showMain" sender:self]; }


}
];
}
else{
CCAlertView *ask = [[CCAlertView alloc]initWithTitle:@"Are you already registered" message:nil];
[ask addButtonWithTitle:@"No" block:^{

[PFFacebookUtils logInWithPermissions:_permissions block:^(PFUser *user, NSError *error) {
if(!user){
NSLog(@"Facebook cancelled");
}
else if(user.isNew){

_type = @"facebook";
[self performSegueWithIdentifier:@"showMain" sender:self]; }
else{
[self performSegueWithIdentifier:@"showMain" sender:self]; }

}];

}];
[ask addButtonWithTitle:@"Yes" block:^{
CCAlertView *log = [[CCAlertView alloc]initWithTitle:@"Enter username and password" message:nil];
[log setAlertViewStyle:UIAlertViewStyleLoginAndPasswordInput];
UITextField *un = [log textFieldAtIndex:0];
UITextField *pw = [log textFieldAtIndex:1];
[log addButtonWithTitle:@"Cancel" block:nil];
[log addButtonWithTitle:@"Enter" block:^{
[PFUser logInWithUsernameInBackground:[un text] password:[pw text] block:^(PFUser *user, NSError *error) {
if(user){
[PFFacebookUtils linkUser:user permissions:_permissions block:^(BOOL succeeded, NSError *error) {
if(succeeded){
NSLog(@"linked");
[self performSegueWithIdentifier:@"showMain" sender:self]; }
else{
NSLog(@"couldnt link");
}
}];
}
else{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Oops!" message:[error userInfo] delegate:self cancelButtonTitle:nil otherButtonTitles:@"okay", nil];
[alert show];
}
}];

}];
[log show];
}];
[ask show];
}

}];

关于ios - 检查 Facebook 帐户是否链接到 PFUser,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24871487/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com