所以创建了一个简单的应用程序来测试sendbird服务,它们看起来最好,所以我已经阅读了他们的文档,此时此刻。我做了什么..我在那里遇到了问题,我什么时候需要调用didReceiveMessage或者为什么我的工作没有?
mycode的
- (IBAction)connnect:(id)sender {
[SBDOpenChannel getChannelWithUrl:@"iDict" completionHandler:^(SBDOpenChannel * _Nullable channel, SBDError * _Nullable error) {
if (error != nil) {
NSLog(@"Error 1 : %@", error.localizedDescription);
return;
}
[channel enterChannelWithCompletionHandler:^(SBDError * _Nullable error) {
if (error != nil) {
NSLog(@"Error: %@", error);
return;
}
NSLog(@"Connected to Channel : %@",channel.channelUrl);
// ...
}];
}];
}
- (IBAction)sendMessage:(id)sender {
[self.channel sendUserMessage:@"pop" data:@"Hey" completionHandler:^(SBDUserMessage * _Nullable userMessage, SBDError * _Nullable error) {
if (error != nil) {
NSLog(@"Error: %@", error);
return;
}
}];
}
- (void)channel:(SBDBaseChannel * _Nonnull)sender didReceiveMessage:(SBDBaseMessage * _Nonnull)message {
if (sender == self.channel) {
NSLog(@"From Button.Message Received From %@ message is : %@ in channel :",sender.description,message.description);
} else {
NSLog(@"Failed");
}
}
@end
答案 0 :(得分:1)
您是否将当前班级注册为频道代表?您需要执行此操作,以便在频道收到消息时,它将使用收到的消息呼叫您的代理。
所以在你的课堂上,我假设它是一个UIViewController,声明它符合这样:
@interface OpenChannelViewController : ViewController<SBDChannelDelegate>
@end
在viewDidLoad中的某个位置,您应该将此类添加到频道委托。
- (void)viewDidLoad {
[SBDMain addChannelDelegate:self identifier:UNIQUE_HANDLER_ID];
}
现在您应该收到消息。信息来自这里: https://docs.sendbird.com/ios?_ga=1.152151677.594130729.1491427400#open_channel_3_receiving_messages
祝你好运!