Ios Quickblox错误:您未连接且未授权
我知道这个问题已经被问了很多次了,但是没有一个解决了我的问题 错误域=com.quickblox.chat Code=401“密码未验证” 实际上我已经试过了:Ios Quickblox错误:您未连接且未授权,ios,objective-c,quickblox,Ios,Objective C,Quickblox,我知道这个问题已经被问了很多次了,但是没有一个解决了我的问题 错误域=com.quickblox.chat Code=401“密码未验证” 实际上我已经试过了: - (void)viewDidLoad { [super viewDidLoad]; appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; NSLog(@"bdsfbd %@",chatuserobj.fullNa
- (void)viewDidLoad
{
[super viewDidLoad];
appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
NSLog(@"bdsfbd %@",chatuserobj.fullName);
NSLog(@"Chat Id %lu",(unsigned long)chatuserobj.ID);
NSLog(@"Current User %@",[QBSession currentSession].currentUser);
QBUUser *currentUserr = [QBUUser user];
currentUserr.ID = appDelegate.loginUserId;
currentUserr.password = appDelegate.loginUserPassword;
// connect to Chat
[QBRequest logInWithUserLogin:appDelegate.loginUser password:appDelegate.loginUserPassword successBlock:^(QBResponse *response, QBUUser *user)
{
chatDialog = [[QBChatDialog alloc] initWithDialogID:NULL type:QBChatDialogTypePrivate];
chatDialog.occupantIDs = @[@(chatuserobj.ID)];
[QBRequest createDialog:chatDialog successBlock:^(QBResponse *response, QBChatDialog *createdDialog)
{
NSLog(@"Created Dialog %@",createdDialog);
} errorBlock:^(QBResponse *response)
{
NSLog(@"Error %@",response);
}];
} errorBlock:^(QBResponse *response) {
}];
[[QBChat instance] connectWithUser:chatuserobj completion:^(NSError * _Nullable error)
{
NSLog(@"USer is Connected %@",error.description);
[self startChat];
}];
[QBSettings setKeepAliveInterval:30];
[QBSettings setAutoReconnectEnabled:YES];
}
还有这个
-(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(@"Completed: %@",error.description);
}];
}
我不知道我错在哪里。请指出我的错误
编辑:再次加载
- (void)viewDidLoad
{
[super viewDidLoad];
// connect to Chat
[[QBChat instance] connectWithUser:currentUserr completion:^(NSError * _Nullable error)
{
NSLog(@"USer is Connected %@",error.description);
}];
dispatch_async(dispatch_get_main_queue(), ^(void)
{
[self chat];
});
dispatch_async(dispatch_get_main_queue(), ^(void)
{
[self startChat];
});
}
聊天是为私人组或一对一连接创建对话框的方法
-(void)chat
{
chatDialog = [[QBChatDialog alloc] initWithDialogID:NULL type:QBChatDialogTypePrivate];
chatDialog.occupantIDs = @[@(chatuserobj.ID)];
[QBRequest createDialog:chatDialog successBlock:^(QBResponse *response, QBChatDialog *createdDialog) {
} errorBlock:^(QBResponse *response) {
}];
}
并启动聊天室进行实际通信
-(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(@"Completed: %@",error.description);
}];
}
现在这个错误发生了
UserInfo={nsLocalizedRecoverysSuggestion=您没有连接到聊天室。
[[QBChat instance] connectWithUser:chatuserobj completion:^(NSError * _Nullable error)
{
NSLog(@"USer is Connected %@",error.description);
}];
此方法用于将您自己连接到聊天室,而不是您的对手。此外,为了使用此方法连接,您的QBUUser实例必须将有效密码设置为password属性。
基本上,您需要将自己连接到聊天室,然后开始创建对话框和发送消息。
- (void)viewDidLoad
{
[super viewDidLoad];
// connect to Chat
[[QBChat instance] connectWithUser:currentUserr completion:^(NSError * _Nullable error)
{
NSLog(@"USer is Connected %@",error.description);
dispatch_async(dispatch_get_main_queue(), ^(void)
{
[self chat];
});
dispatch_async(dispatch_get_main_queue(), ^(void)
{
[self startChat];
});
}];
}
和启动聊天室和聊天室的方法相同。当我使用连接自己时,效果很好,不会出现错误。但是当我发送消息时,再次出现这种情况,您没有连接聊天室。在这里您可以看到我的代码