ios - 解析 : PFUser signUpInBackgroundWithBlock causing exception when trying to convert anonymous user to regular

标签 ios xcode parse-platform

我在 ios 上使用 Parse;这是我使用 Parse 的第三个应用程序,但也是我使用匿名用户函数的第一个应用程序。

我正在尝试将匿名用户转换为普通用户:

[PFAnonymousUtils logInWithBlock:^(PFUser *user, NSError *error) {
    if (error) {
        DLog(@"Anonymous login failed.");
        handler(NO, @"anonymous login failed");
    } else {
        DLog(@"Anonymous user logged in.");
        MyParseUser *myUser = [MyParseUser currentUser];
        if ([PFAnonymousUtils isLinkedWithUser:myUser]) {
            DLog(@"still anonymous");
        } else {
            DLog(@"not anonymous");
        }
        [myUser setParseUserForInstallation]; // usually overkill
        NSString *username = myUser.username;
        NSString *pass = @"password";
        myUser.password = pass;
        DLog(@"Anonymous user has username %@, password %@", username, pass);
        [(PFUser*)myUser signUpInBackgroundWithBlock:^(BOOL success, NSError *error) {
            if (success) {
                DLog(@"signup succeeded");
                handler(YES, myUser);
            } else if (error) {
                DLog(@"Uh oh. An error occurred: %@", error);
                handler(NO, error);
            } else {
                DLog(@"signup didn't throw error, but user not created correctly");
                handler(NO, nil);
            }
        }];
    }
}];

...但是 signUpInBackgroundWithBlock 导致异常:

"Cannot sign up an existing user."

为什么?

最佳答案

事实证明,在调用 signUpInBackgroundWithBlock 时,只有一个对匿名用户无效的用户名字符串:它已经拥有的那个! Parse 似乎认为匿名用户和非匿名用户是分开的,所以就像两个普通用户一样,他们不能共享相同的用户名。这修复了它:

        NSString *username = [MyParseUser randomStringWithLength:10];
        myUser.username = username;

(随机字符串创建者的细节在这里不重要)

关于ios - 解析 : PFUser signUpInBackgroundWithBlock causing exception when trying to convert anonymous user to regular,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24561165/

相关文章:

swift - 如何从 Parse 检索文件以显示在 PFQueryTableVIewController 上?

ios - 为什么我在设置 CIAdditionCompositing 过滤器时会看到 NSUnknownKeyException?

ios - 检查是否在核心数据中设置了属性?

objective-c - Objective C 文件读取过程中出现异常?

ios - 为什么我只得到 PFFile 的 2 个对象,而 String 却得到 10 个对象?

arrays - 警告 : A long-running operation is being executed on the main thread. 尝试一下!获取数据()。 swift

ios - 如何获得 "rotate"一种颜色的色调?

iphone - 如何在 iOS 上获取当前位置?

c++ - SDL 缺少 x86_64 架构

php - 如何将数据从iphone发送/存储到mysql数据库并在网页上显示结果