QuickBlox - QBChatDialogTypePublicGroup:对话框必须在内存缓存中

QuickBlox - QBChatDialogTypePublicGroup : Dialog have to be in memory cache

朋友您好,我已经使用 QuickBlox 创建了一个应用程序。我要从管理面板创建一个 10 QBChatDialogTypePublicGroup。它是静态的。

我想从 quickblox 管理面板创建静态 public 组并与该组中的任何用户聊天。

我正在 viewController 中获取所有组并显示它。然后用户可以选择任何群组聊天 publicly。

我正在使用 quickblox 框架与用户聊天。我完成了 QBChatDialogTypePrivate 一对一用户作弊。

登录:

- (void)loginWithQuickBlox{

    NSString *emaiAddress = [[NSUserDefaults standardUserDefaults] objectForKey:@"UserLogin"];
    NSString *password = [[NSUserDefaults standardUserDefaults] objectForKey:@"UserPassword"];

    [QBRequest logInWithUserLogin:emaiAddress password:password successBlock:^(QBResponse *response, QBUUser *user)
     {
         [[NSUserDefaults standardUserDefaults]setObject:[NSString stringWithFormat:@"%ld",(unsigned long)user.ID] forKey:@"USerLoginID"];
         [self loginWithQuickBloxChat:user];

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

使用 QuickBloxChat 登录

- (void)loginWithQuickBloxChat:(QBUUser *)selectedUser {

    QBUUser *selectedUserx = [QBUUser user];
    selectedUserx.login = [[NSUserDefaults standardUserDefaults] objectForKey:@"UserLogin"];
    selectedUserx.password = [[NSUserDefaults standardUserDefaults] objectForKey:@"UserPassword"];
    selectedUserx.ID = [[[NSUserDefaults standardUserDefaults] objectForKey:@"USerLoginID"] integerValue];

    NSLog(@"Currunt User  : %@", [QBSession currentSession].currentUser);

    [ServicesManager.instance logInWithUser:selectedUserx completion:^(BOOL success, NSString *errorMessage)
    {
        [[QBChat instance] connectWithUser:selectedUserx completion:^(NSError * _Nullable error) {

        }];

         if (success)
         {
             NSLog(@"Login in Quickblox : %@",selectedUser);
             [self getPublicGroup];
         }
         else
         {
             NSLog(@"Error in QuickBlox : %@",errorMessage);
         }
    }];
}

获取Public组

- (void)getPublicGroup {

     NSMutableDictionary *extendedRequest = @{@"type" : @(1)}.mutableCopy;
     QBResponsePage *page = [QBResponsePage responsePageWithLimit:100 skip:0];
     [QBRequest dialogsForPage:page extendedRequest:extendedRequest successBlock:^(QBResponse *response, NSArray *dialogObjects, NSSet *dialogsUsersIDs, QBResponsePage *page) {
     publicGroupArray = dialogObjects.mutableCopy;
     NSLog(@"Public Group : %@",publicGroupArray);
     [self.groupCollectionview reloadData];

    } errorBlock:^(QBResponse *response) {

    }];
}

Select 任何一个群组并与 ChatViewcontroller 聊天

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    QBChatDialog *groupChatDialog = [publicGroupArray objectAtIndex:indexPath.row];
    ChatViewController *chatViewController = [[ChatViewController alloc] init];
    chatViewController.dialog = groupChatDialog;
    chatViewController.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:chatViewController animated:YES];
}

所有程序都运行良好,但是当我从 ChatViewController 发送消息时,它会给我错误

Assertion failure in -[QMChatService sendMessage:toDialogID:saveToHistory:saveToStorage:completion:], All/September/21/ChatApp/Pods/QMServices/QMChatService/QMChatService/QMChatService.m:1338

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Dialog have to be in memory cache!' *** First throw call stack:

您正在尝试将核心 SDK 方法与 QMServices 的方法相结合。

QBRequest 是 Quickblox SDK 的一部分,QMServices 是高级 API 聊天功能,包括:

  1. 用于登录到 Quickblox REST 和 XMPP 的身份验证服务。
  2. 消息、对话和用户的收件箱持久存储和内存存储。

如果您想使用 QMServices 获取对话框,请尝试以下方法:

- (void)loadDialogWithID:(NSString *)dialogID completion:(nullable void (^)(QBChatDialog * _Nullable loadedDialog))completion;

示例:

[ServicesManager.instance.chatService loadDialogWithID:dialogID
                                                completion:^(QBChatDialog * _Nullable loadedDialog)
 {

}];

此方法将从服务器加载对话框,加入它(如果对话框的类型是组)并存储在内存和 CoreDate 中。

如果您想使用 SDK 的核心方法获取对话框,您应该自己实现所有描述的操作。