gpt4 book ai didi

ios - 如何在XMPP中获取选定用户的聊天记录

转载 作者:行者123 更新时间:2023-11-28 19:58:35 25 4
gpt4 key购买 nike

我是xmpp的新手,我需要存储和显示用户的聊天记录。我在使用以下代码时获得了完整的历史记录。我只需要所选用户的聊天记录。

NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
XMPPMessageArchivingCoreDataStorage *xmppMessageArchivingCoreDataStorage=[XMPPMessageArchivingCoreDataStorage sharedInstance];
NSManagedObjectContext *context = [xmppMessageArchivingCoreDataStorage mainThreadManagedObjectContext];
NSEntityDescription *messageEntity = [NSEntityDescription entityForName:@"XMPPMessageArchiving_Message_CoreDataObject" inManagedObjectContext:context];

fetchRequest.entity = messageEntity;

NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"timestamp" ascending:YES];
fetchRequest.sortDescriptors = [NSArray arrayWithObject:sortDescriptor];
NSError *error = nil;
NSArray *results = [context executeFetchRequest:fetchRequest error:&error];
[self print:[[NSMutableArray alloc]initWithArray:results]];

如何获取特定用户的聊天记录,。我已经搜索了很多但没有成功

最佳答案

试试这个

- (void)loadChatHistoryWithUserName:(NSString *)userName
{
NSString *userJid = [NSString stringWithFormat:@"%@@%@",userName,self.hostName];
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, userJid];
request.predicate = predicate;
NSArray *messages = [moc executeFetchRequest:request error:&error];
}

关于ios - 如何在XMPP中获取选定用户的聊天记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25178468/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com