0

我正在尝试在我的应用程序中实现聊天模块。我已成功完成简单聊天演示Login并将其Register处理到我的应用程序中。它还返回离线和在线用户的用户数组。

现在成功登录后,我得到以下日志:-

error:
2012-12-07 14:50:07.056 App[5324:790b] QBChatService/xmppStreamDidConnect
2012-12-07 14:50:08.285 App[5324:790f] QBChatService/xmppStreamDidAuthenticate
2012-12-07 14:51:08.291 App[5324:711f] QBChatService/xmppStreamDidDisconnect, error=Error Domain=GCDAsyncSocketErrorDomain Code=7 "Socket closed by remote peer" UserInfo=0xb982330 {NSLocalizedDescription=Socket closed by remote peer}

而且我无法在我的应用程序中接收聊天消息。

有什么建议么 ?

编辑 :-

在我的应用程序中,登录完成后,我将登录请求发送到 QuickBlox API

if(loginDone)
{
     NSString *userName = [_textUsername.text stringByReplacingOccurrencesOfString:@"@" withString:@"_"];
     NSString *userPass = [_textPassword.text stringByReplacingOccurrencesOfString:@"@" withString:@"_"];

     // Authenticate user
     [QBUsers logInWithUserLogin:userName password:userPass delegate:self context:userPass];
} 

 #pragma mark -
#pragma mark QBActionStatusDelegate

// QuickBlox API queries delegate
-(void)completedWithResult:(Result *)result  context:(void *)contextInfo
{    
    // QuickBlox User authentication result
    if([result isKindOfClass:[QBUUserLogInResult class]])
    {
        // Success result
        if(result.success)
        {
            QBUUserLogInResult *res = (QBUUserLogInResult *)result;

            // save current user
            [[DataManager shared] setCurrentUser: res.user];
            NSLog(@"%@",res.user);

            [[[DataManager shared] currentUser] setPassword:(NSString *)contextInfo];
            NSLog(@"%@",res.user);

            // Login to Chat
            [QBChat instance].delegate = self;
            [[QBChat instance] loginWithUser:[[DataManager shared] currentUser]];

            // Register as subscriber for Push Notifications
            [QBMessages TRegisterSubscriptionWithDelegate:nil];

            // send request for getting user's filelist
            PagedRequest *pagedRequest = [[PagedRequest alloc] init];
            [pagedRequest setPerPage:10];

            [QBContent blobsWithPagedRequest:pagedRequest delegate:self];

            [pagedRequest release];
        }
        else
        {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Errors"
                                                            message:[result.errors description]
                                                           delegate:self
                                                  cancelButtonTitle:@"Ok"
                                                  otherButtonTitles: nil];
            alert.tag = 1;
            //[alert show];
            [alert release];

            [HUD hide:YES];
            [self AfterLoginController];
        }
    }
}

-(void)completedWithResult:(Result *)result
{
    if([result isKindOfClass:[QBUUserLogInResult class]]) // QuickBlox User authentication result
    {
        // Success result
        if(result.success)
        {
            // If we are authenticating through Twitter/Facebook - we use token as user's password for Chat module
            [self completedWithResult:result context:[BaseService sharedService].token];
        }
    }
    else if ([result isKindOfClass:[QBCBlobPagedResult class]])
    {
        // Success result
        if(result.success){
            QBCBlobPagedResult *res = (QBCBlobPagedResult *)result;

            // Save user's filelist
            [DataManager shared].fileList = [[res.blobs mutableCopy] autorelease];

            AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication] delegate];
            [app startsendPresenceTimer];

            [HUD hide:YES];            
            [self AfterLoginController];
        }
    }
    else
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Errors"
                                                        message:[result.errors description]
                                                       delegate:self
                                              cancelButtonTitle:@"Ok"
                                              otherButtonTitles: nil];
        alert.tag = 1;
        //[alert show];
        [alert release];

        [HUD hide:YES];
        [self AfterLoginController];
    }
}

现在在 AppDelegate 中:-

- (void) startsendPresenceTimer
{
    [QBChat instance].delegate = self;

    // send presence
    if(self.sendPresenceTimer == nil)
    {
        self.sendPresenceTimer = [NSTimer scheduledTimerWithTimeInterval:10 target:self selector:@selector(sendPresence) userInfo:nil
                                                                 repeats:YES];
    }

    if (self.requesAllUsersTimer == nil)
    {
        self.requesAllUsersTimer= [NSTimer scheduledTimerWithTimeInterval:10 target:self selector:@selector(updateUsers) userInfo:nil repeats:YES];
    }
    [self.requesAllUsersTimer fire];
}

// send presence
- (void)sendPresence{
    // presence in QuickBlox Chat
    [[QBChat instance] sendPresence];
    // presence in QuickBlox
    [QBUsers userWithExternalID:1 delegate:nil];
}

- (void)updateUsers
{
    // Retrieve all users
    PagedRequest* request = [[PagedRequest alloc] init];
    request.perPage = 100; // 100 users
    [QBUsers usersWithPagedRequest:request delegate:self];
    [request release];
}
4

1 回答 1

2

您是否定期发送出席信息?它需要因为聊天服务器必须知道你是在线还是离线。

查看QuickBlox 聊天设置指南,行

请记住,QuickBlox 它是简单的 XMPP 聊天,...

只写一行

[NSTimer scheduledTimerWithTimeInterval:30 target:[QBChat instance] selector:@selector(sendPresence) userInfo:nil repeats:YES];

应用程序将每 30 秒发送一次出席信息

于 2012-12-07T09:59:22.927 回答