获取openfire聊天记录

时间:2015-05-15 14:16:13

标签: ios xmpp openfire browser-history nslog

我无法从开火中获取历史。我正在使用XMPP Framework

如何从open fire存档获取聊天记录并在nslog中打印历史数据?

2 个答案:

答案 0 :(得分:1)

您需要在openfire中启用该选项以获取聊天记录。 登录openfire,进入群聊,然后转到群聊设置,然后转到历史记录设置,然后选择显示整个聊天记录选项。

答案 1 :(得分:1)

在加入xmpp组时,您必须在xmpp核心数据库中编写以下商店消息代码。

storage = [XMPPMessageArchivingCoreDataStorage   sharedInstance];
moc = [storage mainThreadManagedObjectContext];
XMPPMessageArchiving *xmppMessageArchivingModule = [[XMPPMessageArchiving alloc] initWithMessageArchivingStorage:storage];
[xmppMessageArchivingModule setClientSideMessageArchivingOnly:YES];
[xmppMessageArchivingModule activate:xmppStream];
[xmppMessageArchivingModule addDelegate:self delegateQueue:dispatch_get_main_queue()];

在您输入特定组后,您必须使用以下代码从xmpp核心数据库获取历史记录: -

XMPPMessageArchivingCoreDataStorage *_xmppMsgStorage = [XMPPMessageArchivingCoreDataStorage sharedInstance];
NSManagedObjectContext *moc = [_xmppMsgStorage mainThreadManagedObjectContext];
NSEntityDescription *entityDescription = [NSEntityDescription entityForName:@"XMPPMessageArchiving_Message_CoreDataObject"                                                   inManagedObjectContext:moc];
NSFetchRequest *request = [[NSFetchRequest alloc]init];
[request setEntity:entityDescription];
NSError *error;
NSString *predicateFrmt = @"bareJidStr == %@";
NSPredicate *predicate = [NSPredicate predicateWithFormat:predicateFrmt, [NSString stringWithFormat:@"%@%@",GroupName,GROUP_CHAT_DOMAIN]];
request.predicate = predicate;
NSArray *messages = [moc executeFetchRequest:request error:&error];