Hello Friends我用QuickBlox
创建了一个应用程序。我将从管理面板创建一个10 QBChatDialogTypePublicGroup
。它是静态的。
我想从quickblox
管理面板创建静态公开群组,并与该群组中的任何用户聊天。
我在viewController中获取此组并显示它。然后用户可以选择任何组进行公开聊天。
我正在使用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);
}
}];
}
获取公共群组
- (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) {
}];
}
选择任意一个群组并与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
发送消息时,它会给我错误
断言失败 - [QMChatService 的sendMessage:toDialogID:saveToHistory:saveToStorage:完成:] 所有/月/ 21 / ChatApp /荚/ QMServices / QMChatService / QMChatService / QMChatService.m:1338
由于未捕获的异常而终止应用 'NSInternalInconsistencyException',原因:'对话必须在 内存缓存!' ***首先抛出调用堆栈:
答案 0 :(得分:1)
您正在尝试将核心SDK方法与QMServices方法结合使用。
QBRequest是Quickblox SDK的一部分,QMServices是聊天功能的高级API,包括:
如果您想使用QMServices获取对话框,请尝试以下方法:
- (void)loadDialogWithID:(NSString *)dialogID completion:(nullable void (^)(QBChatDialog * _Nullable loadedDialog))completion;
示例:
[ServicesManager.instance.chatService loadDialogWithID:dialogID
completion:^(QBChatDialog * _Nullable loadedDialog)
{
}];
此方法将从服务器加载对话框,加入它(如果对话框的类型是组)并存储在内存和CoreDate中。
如果您想使用SDK的核心方法获取对话框,您应该自己实施所有描述的操作。