2015-09-25 103 views
0

寻求在我们的iOS应用程序中实现QuickBlox的一些帮助。我们似乎无法解决发送消息后的问题QuickBlox会返回当定时器滴答事件调用该块时先前发送的所有消息。任何帮助将非常感激!发送QuickBlox消息后,它将返回先前发送的所有消息

QBResponsePage *page = [QBResponsePage responsePageWithLimit:10 skip:0]; 

    [QBRequest dialogsForPage:page extendedRequest:nil successBlock:^(QBResponse *response, NSArray *dialogObjects, NSSet *dialogsUsersIDs, QBResponsePage *page) 
    { 
     QBChatDialog *dialog=[dialogObjects objectAtIndex:0]; 
     [QBRequest messagesWithDialogID:dialog.ID extendedRequest:nil forPage:page successBlock:^(QBResponse *response, NSArray *messages, QBResponsePage *responsePage) 
     { 
      [self.items removeAllObjects]; 
      [self.items addObjectsFromArray:messages]; 
      [self finishSendingMessageAnimated:YES]; 

     } errorBlock:^(QBResponse *response) { 
      NSLog(@"error: %@", response.error); 
     }]; 


    } errorBlock:^(QBResponse *response) { 

    }]; 

这里是我们采取的步骤:进口所有QuickBlox类到我们的项目 1)。

2)在我的应用委托类设置QuickBlox

[QBApplication sharedApplication].applicationId = (removed); 
[QBConnection registerServiceKey:@“(removed)”]; 
[QBConnection registerServiceSecret:@“(removed)”]; 
[QBSettings setAccountKey:@“(removed)”]; 

3)的所有凭证然后创建已导入QMChatViewController的亚类

4)进口NMPaginatorDelegate和Cretae UsersPaginator对象,(给我用户列表)

5)在点击特定的用户调用我们创建并在其viewDidLoad中的子类写下面的代码:

QBUUser *currentUser = [QBUUser user]; 
currentUser.ID = LoginUser.ID; 
currentUser.password = LoginUser.login; 

[[QBChat instance] addDelegate:(id)self]; 
[[QBChat instance] loginWithUser:currentUser]; 

loginWithUser后称为

BOOL chlLogion =[[QBChat instance]isLoggedIn]; 
    NSLog(@"Loggin IN Status :- %hhd”,chlLogion); 

日志打印: - 2015年9月22日16:04:31.911 AppName的[2263:96572] [ChatService]连接到聊天,主持人:chat.quickblox.com,用户JID:[email protected]/7DE2CD1E-481F-4922-B21D-8EB14BF8B55F 2015年9月22日16:04:42.978 AppName的[2263:96225]洛IN状态: - 0

注: - 脱保护

[[QBChat instance] sendMessage:message]; 

该代码被清除,并且您的sdks显示它的选项,但那也不起作用。

并设置其委托方法。

  • (无效)chatDidConnect { }
  • (无效)chatDidAccidentallyDisconnect { }
  • (无效)chatDidReconnect { }
  • (无效)chatDidReceiveMessage:(QBChatMessage *)消息{ 的NSLog (@“Received Message%@”,message); }
  • (无效)chatDidNotSendMessage:(QBChatMessage *)消息错误:(NSError *)错误{ }
  • (无效)chatDidDeliverMessageWithID:(的NSString *)MESSAGEID { }

然而,它之后只是调用1委托“chatDidConnect”,而不调用另一个委托。 而在发送消息我设置:

QBChatDialog *chatDialog = [[QBChatDialog alloc]initWithDialogID:[NSString stringWithFormat:@"%lu",(unsigned long)LoginUser.ID] type:QBChatDialogTypePrivate]; 
    [email protected][@(SelectedChatUser.ID)]; 
    chatDialog.name = @"school friends"; 

    [QBRequest createDialog:chatDialog successBlock:^(QBResponse *response, QBChatDialog *createdDialog) { 

     _dialog=createdDialog; 
     QBChatMessage *message = [QBChatMessage message]; 

     message.text = text; 
     message.senderID = senderId; 
     message.recipientID=createdDialog.recipientID; 
     message.deliveredIDs=[createdDialog.occupantIDs objectAtIndex:1]; 
     message.dialogID=[NSString stringWithFormat:@"%@",createdDialog.ID]; 
     [email protected]"Nick Simulator"; 
     message.dateSent = [NSDate date]; 

     [self.items addObject:message]; 

     [createdDialog sendMessage:message]; 
     [self finishSendingMessageAnimated:YES]; 

    } errorBlock:^(QBResponse *response) { 

    }]; 

但扔的代码消息无法发送,我们没有得到任何消息扔委托。

6)之后,我切换到新的方法发送消息。写下面的代码发送消息:

- (void)didPressSendButton:(UIButton *)button 
     withMessageText:(NSString *)text 
       senderId:(NSUInteger)senderId 
    senderDisplayName:(NSString *)senderDisplayName 
        date:(NSDate *)date { 

QBChatDialog *chatDialog = [[QBChatDialog alloc]initWithDialogID:[NSString stringWithFormat:@"%lu",(unsigned long)LoginUser.ID] type:QBChatDialogTypePrivate]; 
    [email protected][@(SelectedChatUser.ID)]; 
    chatDialog.name = @"school friends"; 
     [QBRequest createDialog:chatDialog successBlock:^(QBResponse *response, QBChatDialog *createdDialog) { 

     _dialog=createdDialog; 
     QBChatMessage *message = [QBChatMessage message]; 

     message.text = text; 
     message.senderID = senderId; 
     message.recipientID=createdDialog.recipientID; 
     message.deliveredIDs=[createdDialog.occupantIDs objectAtIndex:1]; 
     message.dialogID=[NSString stringWithFormat:@"%@",createdDialog.ID]; 
     [email protected]"Nick Simulator"; 
     message.dateSent = [NSDate date]; 

     [self.items addObject:message]; 

     [QBRequest createMessage:message successBlock:^(QBResponse *response, QBChatMessage *createdMessage) { 
      NSLog(@"success: %@", createdMessage); 
     } errorBlock:^(QBResponse *response) { 
      NSLog(@"ERROR: %@", response.error); 
     }]; 
    [self finishSendingMessageAnimated:YES]; 

     } errorBlock:^(QBResponse *response) { 

    }]; 
+0

感谢Mike的详细问题。哪些代码每次都会返回所有消息?这[QBRequest messagesWithDialogID ..]? –

回答

1

QBResponsePage的dialogsForpage将返回所有以前的消息。因此,跳过已有的消息计数将只返回最新的消息。

let page = QBResponsePage.(limit:10, skip: message count that you already have) 
let parameters = ["sort_desc" : "date_sent"] 
QBRequest.messagesWithDialogID(currentDialog.ID!, 
           extendedRequest: parameters, 
           forPage: resPage, 
           successBlock:{ (response: QBResponse, messages: [QBChatMessage]?, page: QBResponsePage?) -> Void in 
           /**your code**/ 
           }