尋求在我們的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) {
}];
感謝Mike的詳細問題。哪些代碼每次都會返回所有消息?這[QBRequest messagesWithDialogID ..]? –