希望获得一些帮助将QuickBlox应用到我们的iOS应用程序中。我们似乎无法解决发送消息后的问题QuickBlox返回当计时器ticks事件调用块时先前已发送的所有消息。任何帮助将不胜感激!
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) {
}];
以下是我们采取的步骤: 1)将所有QuickBlox类导入到我们的项目中。
2)在My App Delegate Class中设置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);
Log Print: - 2015-09-22 16:04:31.911 AppName [2263:96572] [ChatService]连接到聊天,主持人:chat.quickblox.com,用户JID:5434136-28329@chat.quickblox.com / 7DE2CD1E-481F-4922-B21D-8EB14BF8B55F 2015-09-22 16:04:42.978 AppName [2263:96225]登录状态: - 0
注意: - 堕落
[[QBChat instance] sendMessage:message];
该代码已被删除,并且您的sdks显示了它的选项,但这也是无效的。
并设置其委托方法。
然而,在没有调用另一个委托之后,它只调用了1个委托“chatDidConnect”。 在发送消息我正在设置:
QBChatDialog *chatDialog = [[QBChatDialog alloc]initWithDialogID:[NSString stringWithFormat:@"%lu",(unsigned long)LoginUser.ID] type:QBChatDialogTypePrivate];
chatDialog.occupantIDs=@[@(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];
message.senderNick=@"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];
chatDialog.occupantIDs=@[@(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];
message.senderNick=@"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 :(得分:2)
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**/
}