我正在使用XMPP在iOS中开发一个聊天应用程序。到目前为止,我已经成功地实现并测试了一个单用户聊天场景,即发送、接收、保存和检索消息。
他们现在面临的问题是,现在在处理多用户聊天场景时,他们收到了它,但无法使用XMPP消息归档保存它们,因此也无法检索它们。
有谁经历过这个过程/问题吗?
提前感谢
groupchat
类型的消息可能保存在XMPPRoom.xcdatamodel
中,您需要在xmpp设置中初始化XMPPRoomCoreDataStorage
,如:
XMPPRoomCoreDataStorage *xmppRoomStorage = [[XMPPRoomCoreDataStorage alloc] init];
因此,这个类实现了一个方法,将所有消息ROOM插入正确的数据模型中(在我们的例子中,所有传出和传入的消息都保存在XMPPRoom.xcdatamodel中)
- (void)insertMessage:(XMPPMessage *)message
outgoing:(BOOL)isOutgoing
forRoom:(XMPPRoom *)room
stream:(XMPPStream *)xmppStream
XEP-0045更多信息http://xmpp.org/extensions/xep-0045.html
您可以将此代码用于保存房间消息
NSString *xmppRoomJIDString = [NSString stringWithFormat:@"%@@conference.your_host", @"your_room_name"];
XMPPJID *roomJID = [XMPPJID jidWithString:xmppRoomJIDString];
XMPPRoomCoreDataStorage *roomCoreDataStorage = [XMPPRoomCoreDataStorage sharedInstance];
XMPPRoom *xmppRoom = [[XMPPRoom alloc]
initWithRoomStorage:roomCoreDataStorage
jid:roomJID
dispatchQueue:dispatch_get_main_queue()];
[xmppRoom activate:xmppStream];
[xmppRoom addDelegate:self delegateQueue:dispatch_get_main_queue()];
[xmppRoom joinRoomUsingNickname:@"your_nicke_name" history:nil];
[xmppRoom fetchConfigurationForm];