OStack程序员社区-中国程序员成长平台

标题: ios - 需要 Quicklox token [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 20:57
标题: ios - 需要 Quicklox token

我在我的应用程序中使用 quickblox。我做了我的用户注册、用户登录和聊天。我第一次登录时一切正常。如果我按 home 并再次进入应用程序,我会来到我的 viewController 页面。用户自动注销。当我尝试登录时,它说,需要 token 。

我已将 session 身份验证放入 appdelegate

 [QBAuth createSessionWithDelegate:self]
    -(void)viewDidAppearBOOL)animated
    {

    if([LocalStorageService shared].currentUser == nil)// check if user is logged in
    {
        NSCharacterSet *nonalphanumericSet = [[ NSCharacterSet alphanumericCharacterSet] invertedSet];

        [QBUsers logInWithUserLogin:[[[PFUser currentUser].username componentsSeparatedByCharactersInSet:nonalphanumericSet ] componentsJoinedByString"1"] password"password" delegate:self];
    }
    }

    - (void)completedWithResultResult *)result
    {
    if(result.success && [result isKindOfClassBUUserLogInResult.class])
    {
        // Success, do something
        QBUUserLogInResult *userResult = (QBUUserLogInResult *)result;
        NSLog(@"Logged In user=%@", userResult.user);


            userResult.user.password =@"password";

        // Save current user
        //
        [[LocalStorageService shared] setCurrentUser: userResult.user];


        // Login to QuickBlox Chat
        //
        [[ChatService instance] loginWithUser:[LocalStorageService shared].currentUser completionBlock:^{

            NSLog(@"chat logged successfully");


        }];

        // Errors
    }
    else
    {
        NSString *errorMessage = [[result.errors description] stringByReplacingOccurrencesOfString"(" withString""];
        errorMessage = [errorMessage stringByReplacingOccurrencesOfString")" withString""];

        UIAlertView *alert = [[UIAlertView alloc] initWithTitle"Errors"
                                                        message:errorMessage
                                                       delegate:nil
                                              cancelButtonTitle"Ok"
                                              otherButtonTitles: nil];
        [alert show];

    }

}



Best Answer-推荐答案


token is required表示您正在尝试执行请求,但您还没有创建 session

您可以重现此问题,只需一一执行 2 个请求:

[QBAuth createSessionWithDelegate:self];
[QBUsers logInWithUserLogin:... delegate:self];

在此序列之后,您将得到“需要 token ”

要摆脱这种情况,您应该等待创建 session 请求完成并执行下一个请求:

[QBAuth createSessionWithDelegate:self];

...

- (void)completedWithResultResult *)result{
     if(result.success && [result isKindOfClassBAAuthSessionCreationResult.class]){

         // you got token here - perform any other requests after this

         [QBUsers logInWithUserLogin:... delegate:self];

     }
}

这不是您的问题的解决方案,而是解释它发生的原因以及如何解决它

关于ios - 需要 Quicklox token ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22707908/






欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) Powered by Discuz! X3.4