我遇到一个问题,当我在群组类型 QBChatDialogTypePublicGroup 中聊天时收不到消息。但是我可以在日志中看到消息正在发送给我。根据 quickblox 官方网站中的说明,收到消息时应调用以下方法
- (void)chatRoomDidReceiveMessage:(QBChatMessage )message fromDialogId:(NSString )dialogId
- (void)chatDidNotSendMessage:(QBChatMessage )message toDialogId:(NSString )dialogId error:(NSError *)error
但是上面的委托(delegate)都没有调用。
这是我采取的步骤-
对于登录:-
[QBRequest logInWithUserLogin:[[AppDelegate sharedAppDelegate]getQBUserInstance].login password:[[AppDelegate sharedAppDelegate]getQBUserInstance].password successBlock:^(QBResponse response, QBUUser user) {
NSLog(@"quickblox user id is %lu", (unsigned long)user.ID);
[[NSUserDefaults standardUserDefaults] setValue:[NSString stringWithFormat:@"%lu", (unsigned long)user.ID]forKey:@"QuickbloxUserID"];
[[AppDelegate sharedAppDelegate]getQBUserInstance].ID=user.ID;
// set Chat delegate
[[QBChat instance] addDelegate:self];
// login to Chat
[[QBChat instance] loginWithUser:[[AppDelegate sharedAppDelegate]getQBUserInstance]];
} errorBlock:^(QBResponse *response) {
// error handling
NSLog(@"error: %@", response.error);
}];
-(void) chatDidLogin{
[QBChat instance].keepAliveInterval = 30;
[QBChat instance].autoReconnectEnabled = YES;
[QBChat instance].streamManagementEnabled = YES;
NSLog(@"You have successfully signed in to QuickBlox Chat");
[MyNetWorking endHud];
FMTabBarController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"tabView"];
[AppDelegate sharedAppDelegate].window.rootViewController=vc;
//[self presentViewController:vc animated:YES completion:nil];
}
- (void)chatDidNotLoginWithError:(NSError *)error{
NSLog(@"You have successfully signed in to QuickBlox Chat %@", error.domain);
NSLog(@"You have successfully signed in to QuickBlox Chat %@", error.userInfo);
NSLog(@"You have successfully signed in to QuickBlox Chat %@", error.localizedDescription);
}
- (void)chatDidConnect{
NSLog(@"You have successfully signed in to QuickBlox Chat");
}
- (void)chatDidAccidentallyDisconnect{
NSLog(@"You have successfully signed in to QuickBlox Chat");
}
- (void)chatDidReconnect{
NSLog(@"You have successfully signed in to QuickBlox Chat");
}
要加入群组,我使用了以下代码
groupChatDialog = [[QBChatDialog alloc] initWithDialogID:self.groupChatID type:QBChatDialogTypePublicGroup];
NSLog(@"Chat dialog %@", [QBChat instance].delegates);
// [[QBChat instance] addDelegate:self];
// NSLog(@"Chat dialog %@", [QBChat instance].delegates);
[groupChatDialog setOnJoin:^() {
[[[UIAlertView alloc] initWithTitle:@"FM" message:@"Group Joined Successfully" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:@"Cancel", nil] show];
}];
[groupChatDialog setOnJoinFailed:^(NSError *error) {
[[[UIAlertView alloc] initWithTitle:@"FM" message:error.localizedDescription delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:@"Cancel", nil] show];
NSLog(@"Error is %@", error);
}];
[groupChatDialog join];
************************************************************
To fetch previous chat I have used the following code
************************************************************
QBResponsePage *resPage = [QBResponsePage responsePageWithLimit:20 skip:0];
[QBRequest messagesWithDialogID:self.groupChatID extendedRequest:nil forPage:resPage successBlock:^(QBResponse response, NSArray messages, QBResponsePage *responcePage) {
NSLog(@"messages are %@", messages);
[arrayChat addObjectsFromArray:messages];
[self.tableView reloadData];
} errorBlock:^(QBResponse *response) {
NSLog(@"error: %@", response.error);
}];
为了发送消息,我使用了以下代码
messageToSent = [QBChatMessage message];
[messageToSent setText:_textField.text];
[messageToSent setDateSent:[NSDate date]];
NSMutableDictionary *params = [NSMutableDictionary dictionary];
params[@"save_to_history"] = @YES;
[messageToSent setCustomParameters:params];
[groupChatDialog sendMessage:messageToSent];
_textField.text = @"";
[arrayChat addObject:messageToSent];
[_tableView reloadData];
在此之后我希望调用以下方法
- (void)chatRoomDidReceiveMessage:(QBChatMessage )message fromDialogId:(NSString )dialogId{
NSLog(@"message is %@", message);
}
- (void)chatDidNotSendMessage:(QBChatMessage )message toDialogId:(NSString )dialogId error:(NSError *)error{
[[[UIAlertView alloc] initWithTitle:@"FM" message:error.localizedDescription delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:@"Cancel", nil] show];
NSLog(@"Error is %@", error);
}
但是他们没有被调用,但是他们应该按照网站上的解释被调用。请让我知道我在这里遗漏了什么或我在这里做错了什么。
最佳答案
首先确保你已经设置了QBChat委托(delegate),设置使用下面的代码
QBChat.instance.addDelegate(self)
不过,如果您的委托(delegate)方法没有调用,请确保您已连接到聊天。如果您未连接到聊天,则不会调用代表。
尝试使用下面的代码连接聊天,然后重试。
*Swift代码
QBChat.instance.connect(withUserID: "user_id",
password: "password",
completion: { [weak self] error in
guard let self = self else { return }
if let error = error
print("Error occured while connecting to chat")
} else {
print("successfully connected to chat.")
self.onCompleteAuth?()
}
})
Note: chat connection can be lost for some reasons, 1. lost connection to internet, 2. App went in background or got suspended. 3. if you're presenting controllers like UIImagePickerController, Camera, UIDocumentPickerController etc.
关于ios - Quickblox 聊天室确实收到消息未调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33139412/
我是rails的新手,想在form字段上应用验证。myviewsnew.html.erb.....模拟.rbclassSimulation{:in=>1..25,:message=>'Therowmustbebetween1and25'}end模拟Controller.rbclassSimulationsController我想检查模型类中row字段的整数范围,如果不在范围内则返回错误信息。我可以检查上面代码的范围,但无法返回错误消息提前致谢 最佳答案 关键是您使用的是模型表单,一种显示ActiveRecord模型实例属性的表单。c
我正在尝试编写一个将文件上传到AWS并公开该文件的Ruby脚本。我做了以下事情:s3=Aws::S3::Resource.new(credentials:Aws::Credentials.new(KEY,SECRET),region:'us-west-2')obj=s3.bucket('stg-db').object('key')obj.upload_file(filename)这似乎工作正常,除了该文件不是公开可用的,而且我无法获得它的公共(public)URL。但是当我登录到S3时,我可以正常查看我的文件。为了使其公开可用,我将最后一行更改为obj.upload_file(file
这里有一个很好的答案解释了如何在Ruby中下载文件而不将其加载到内存中:https://stackoverflow.com/a/29743394/4852737require'open-uri'download=open('http://example.com/image.png')IO.copy_stream(download,'~/image.png')我如何验证下载文件的IO.copy_stream调用是否真的成功——这意味着下载的文件与我打算下载的文件完全相同,而不是下载一半的损坏文件?documentation说IO.copy_stream返回它复制的字节数,但是当我还没有下
如何在ruby中调用C#dll? 最佳答案 我能想到几种可能性:为您的DLL编写(或找人编写)一个COM包装器,如果它还没有,则使用Ruby的WIN32OLE库来调用它;看看RubyCLR,其中一位作者是JohnLam,他继续在Microsoft从事IronRuby方面的工作。(估计不会再维护了,可能不支持.Net2.0以上的版本);正如其他地方已经提到的,看看使用IronRuby,如果这是您的技术选择。有一个主题是here.请注意,最后一篇文章实际上来自JohnLam(看起来像是2009年3月),他似乎很自在地断言RubyCL
我正在尝试解析一个文本文件,该文件每行包含可变数量的单词和数字,如下所示:foo4.500bar3.001.33foobar如何读取由空格而不是换行符分隔的文件?有什么方法可以设置File("file.txt").foreach方法以使用空格而不是换行符作为分隔符? 最佳答案 接受的答案将slurp文件,这可能是大文本文件的问题。更好的解决方案是IO.foreach.它是惯用的,将按字符流式传输文件:File.foreach(filename,""){|string|putsstring}包含“thisisanexample”结果的
我正在尝试使用boilerpipe来自JRuby。我看过guide从JRuby调用Java,并成功地将它与另一个Java包一起使用,但无法弄清楚为什么同样的东西不能用于boilerpipe。我正在尝试基本上从JRuby中执行与此Java等效的操作:URLurl=newURL("http://www.example.com/some-location/index.html");Stringtext=ArticleExtractor.INSTANCE.getText(url);在JRuby中试过这个:require'java'url=java.net.URL.new("http://www
我需要一些关于TDD概念的帮助。假设我有以下代码defexecute(command)casecommandwhen"c"create_new_characterwhen"i"display_inventoryendenddefcreate_new_character#dostufftocreatenewcharacterenddefdisplay_inventory#dostufftodisplayinventoryend现在我不确定要为什么编写单元测试。如果我为execute方法编写单元测试,那不是几乎涵盖了我对create_new_character和display_invent
我的工作要求我为某些测试自动生成电子邮件。我一直在四处寻找,但未能找到可以快速实现的合理解决方案。它需要在outlook而不是其他邮件服务器中,因为我们有一些奇怪的身份验证规则,我们需要保存草稿而不是仅仅发送邮件的选项。显然win32ole可以做到这一点,但我找不到任何相当简单的例子。 最佳答案 假设存储了Outlook凭据并且您设置为自动登录到Outlook,WIN32OLE可以很好地完成此操作:require'win32ole'outlook=WIN32OLE.new('Outlook.Application')message=
我正在使用Ruby,我正在与一个网络端点通信,该端点在发送消息本身之前需要格式化“header”。header中的第一个字段必须是消息长度,它被定义为网络字节顺序中的2二进制字节消息长度。比如我的消息长度是1024。如何将1024表示为二进制双字节? 最佳答案 Ruby(以及Perl和Python等)中字节整理的标准工具是pack和unpack。ruby的packisinArray.您的长度应该是两个字节长,并且按网络字节顺序排列,这听起来像是n格式说明符的工作:n|Integer|16-bitunsigned,network(bi
在应用开发中,有时候我们需要获取系统的设备信息,用于数据上报和行为分析。那在鸿蒙系统中,我们应该怎么去获取设备的系统信息呢,比如说获取手机的系统版本号、手机的制造商、手机型号等数据。1、获取方式这里分为两种情况,一种是设备信息的获取,一种是系统信息的获取。1.1、获取设备信息获取设备信息,鸿蒙的SDK包为我们提供了DeviceInfo类,通过该类的一些静态方法,可以获取设备信息,DeviceInfo类的包路径为:ohos.system.DeviceInfo.具体的方法如下:ModifierandTypeMethodDescriptionstatic StringgetAbiList()Obt