使用 XMPPFramework for ios 存储消息? [英] Storing messages using XMPPFramework for ios?

查看:16
本文介绍了使用 XMPPFramework for ios 存储消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不确定如何使用 XMPPFramework 的核心数据来存储传入的消息.有没有人有任何关于如何做到这一点的教程?我看到 User 对象,而这些对象又可以拥有许多资源".收到的每条消息是否都应该是我创建并保留的新资源?

I'm not sure how to use the XMPPFramework's core data to store incoming messages. Does anyone have any tutorials on how to do this? I see User objects, which in turn can have many "resources". Is each message received supposed to be a new resource that I create and persist?

我不知道我的职责是什么,框架提供了哪些关于消息历史的部分.我可以拦截每条传入的消息.那么我是否应该使用核心数据在 Messages 表中创建和存储每条消息?我有一个消息实体.每个 XMPPUser 都会有一个 Message 对象数组.但是,我不会推出自己的解决方案,这将与框架相悖吗?

I do not know what part is my responsibility and what part the framework provides regarding message history. I can intercept every incoming message. Then am I supposed to create and store each message inside a Messages table using core data? I'd have a Message Entity. And each XMPPUser would have an array of Message objects. But then wouldn't I be rolling my own solution, which would be working against the framework?

谢谢!

推荐答案

我知道这是一个旧线程,但由于我目前在 iOS 上使用 XMPP,我必须说 XMPP 中内置了对归档消息的支持.

I know this is an old thread but as I am currently working with XMPP on iOS I must say that there is a built in support for archiving messages in XMPP.

我下载了适用于 iOS 的 XMPP 框架,其中有一个标记为 XEP-0136 的文件夹.通过在实例化 XMPP 客户端的类中使用以下代码行,在 XCode 中导入文件夹并激活客户端存档:

I downloaded the XMPP framework for iOS and in it there is folder marked XEP-0136. Import the folders in XCode and activate client side archiving by using the following lines of code in the class you instantiate XMPP client:

xmppMessageArchivingStorage = [XMPPMessageArchivingCoreDataStorage sharedInstance];
xmppMessageArchivingModule = [[XMPPMessageArchiving alloc] initWithMessageArchivingStorage:xmppMessageArchivingStorage];

以下一行代码使您无需将特定于存档的节发送到 xmpp 服务器最有可能以 service-not-implemented 响应

the following one line of code saves you from sending archive specific stanzas to the xmpp server which will most probably respond with service-not-implemented

[xmppMessageArchivingModule setClientSideMessageArchivingOnly:YES];

[xmppMessageArchivingModule activate:xmppStream];
[xmppMessageArchivingModule  addDelegate:self delegateQueue:dispatch_get_main_queue()];

你已经准备好了.从那一刻起,消息(传出和传入)将存储在框架创建的表中.

And you are set. From that moment on, messages (outgoing and incoming) will be stored in a table created by the framework.

如果您需要更多信息,请发表评论,我会尽快回复您.

If you need more info please comment and i will get back to you.

@PraviJay

我确实喜欢这个:

-(void)testMessageArchiving{
            XMPPMessageArchivingCoreDataStorage *storage = [XMPPMessageArchivingCoreDataStorage sharedInstance];
            NSManagedObjectContext *moc = [storage mainThreadManagedObjectContext];
            NSEntityDescription *entityDescription = [NSEntityDescription entityForName:@"XMPPMessageArchiving_Message_CoreDataObject"
                                                                 inManagedObjectContext:moc];
            NSFetchRequest *request = [[NSFetchRequest alloc]init];
            [request setEntity:entityDescription];
            NSError *error;
            NSArray *messages = [moc executeFetchRequest:request error:&error];

            [self print:[[NSMutableArray alloc]initWithArray:messages]];
}

-(void)print:(NSMutableArray*)messages{
         @autoreleasepool {
            for (XMPPMessageArchiving_Message_CoreDataObject *message in messages) {
                NSLog(@"messageStr param is %@",message.messageStr);
                NSXMLElement *element = [[NSXMLElement alloc] initWithXMLString:message.messageStr error:nil];
                NSLog(@"to param is %@",[element attributeStringValueForName:@"to"]);
                NSLog(@"NSCore object id param is %@",message.objectID);
                NSLog(@"bareJid param is %@",message.bareJid);
                NSLog(@"bareJidStr param is %@",message.bareJidStr);
                NSLog(@"body param is %@",message.body);
                NSLog(@"timestamp param is %@",message.timestamp);
                NSLog(@"outgoing param is %d",[message.outgoing intValue]);
            }
        }
}

希望有帮助:)

这篇关于使用 XMPPFramework for ios 存储消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆