gpt4 book ai didi

ios - 使用 quickblox 发送消息

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:32:38 25 4
gpt4 key购买 nike

我已将 quickblox 集成到我的应用程序中。因为我使用这段代码在 tableview 中获取了所有用户

 QBGeneralResponsePage *page = [QBGeneralResponsePage responsePageWithCurrentPage:1 perPage:100];
[QBRequest usersForPage:page successBlock:^(QBResponse *response, QBGeneralResponsePage *pageInformation, NSArray *users)
{

[_NameArray addObjectsFromArray:users];

}
errorBlock:^(QBResponse *response)
{

}];
}
errorBlock:^(QBResponse *response)
{

NSLog(@"error: %@", response.error);
}];

在 _nameArray 中我有 QBUUSER 对象形式的所有用户信息

QBUUser *obj = [Array objectAtIndex:indexPath.row];
NSString *name = obj.fullname;

在检索所有用户。现在,当 loginUser 单击特定联系人或检索用户时,我会使用此代码创建私有(private)群组一对一通信

-(void)chat
{
chatDialog = [[QBChatDialog alloc] initWithDialogID:NULL type:QBChatDialogTypePrivate];

chatDialog.occupantIDs = @[@(chatuserobj.ID)];

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

} errorBlock:^(QBResponse *response) {

}];



}

主要是在那个 View Controller 中发送和接收消息我已经使用了用于发送消息的文本字段和用于发送消息的显示消息的 TableView 我已经使用了这段代码

    -(void)startChat
{
[[QBChat instance] addDelegate:self];


QBChatMessage *message = [QBChatMessage message];

[message setText:@"Hey there"];


NSMutableDictionary *params = [NSMutableDictionary dictionary];
params[@"save_to_history"] = @YES;
[message setCustomParameters:params];


[chatDialog sendMessage:message completionBlock:^(NSError * _Nullable error)
{
NSLog(@"Message sent");

}];

}

并在委托(delegate)方法下方使用

- (void)chatDidReceiveMessage:(QBChatMessage *)message

我实际上在 quickblox 的管理面板中看到了私有(private)组,但看不到已发送的消息。请帮助我。

最佳答案

而不是你的代码是这样的:

[chatDialog sendMessage:message completionBlock:^(NSError * _Nullable error)
{
NSLog(@"Message sent");

}];

使用以下代码:

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

我使用这样的代码:

  #pragma mark Tool bar Actions
- (void)didPressSendButton:(UIButton *)button
withMessageText:(NSString *)text
senderId:(NSUInteger)senderId
senderDisplayName:(NSString *)senderDisplayName
date:(NSDate *)date {
[[QBChat instance] addDelegate:self];
QBChatMessage *message = [QBChatMessage message];
[message setText:text];
message.senderID = senderId;
message.recipientID= [[NSUserDefaults standardUserDefaults] integerForKey:@"CurrentRecipientID"];
message.dateSent = [NSDate date];
NSMutableDictionary *params = [NSMutableDictionary dictionary];
params[@"save_to_history"] = @YES;
[message setCustomParameters:params];
[QBRequest createMessage:message successBlock:^(QBResponse *response, QBChatMessage *createdMessage) {
NSLog(@"success: %@", createdMessage);
[self.chatSectionManager addMessage:createdMessage];
} errorBlock:^(QBResponse *response) {
NSLog(@"ERROR: %@", response.error);
}];

[self finishSendingMessageAnimated:YES];

}

关于ios - 使用 quickblox 发送消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38301685/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com