使用XMPPFramework为ios存储消息? [英] Storing messages using XMPPFramework for ios?
问题描述
我不知道如何使用XMPPFramework的核心数据来存储传入的消息。有没有人有任何教程如何做到这一点?我看到User对象,这反过来可以有很多资源。收到的每条消息是否应该是我创建和保留的新资源?
我不知道什么部分是我的责任和框架提供的有关消息历史的部分。我可以拦截每个传入的消息。那么我应该使用核心数据在Messages表中创建和存储每条消息吗?
我有一个消息实体。每个XMPPUser都有一个Message对象数组。
谢谢!
我知道这是一个老线程,但因为我目前使用XMPP在iOS上我必须说,有一个内置的支持XMPP中的邮件归档。
我下载了XMPP框架为iOS和在它有文件夹标记为XEP-0136。导入XCode中的文件夹,并通过使用以下代码类实例化XMPP客户端激活客户端存档:
xmppMessageArchivingStorage = [XMPPMessageArchivingCoreDataStorage sharedInstance];
xmppMessageArchivingModule = [[XMPPMessageArchiving alloc] initWithMessageArchivingStorage:xmppMessageArchivingStorage];
以下一行代码可以节省您将归档特定节发送到xmpp服务器
这将很可能响应与服务未实现
[xmppMessageArchivingModule setClientSideMessageArchivingOnly:YES];
[xmppMessageArchivingModule activate:xmppStream];
[xmppMessageArchivingModule addDelegate:self delegateQueue:dispatch_get_main_queue()];
您已设置。从那一刻起,消息(传出和传入)将被存储在框架创建的表中。
如果您需要更多信息,请注释,我将回到
@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 *错误;
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]);
}
}
}
希望它有帮助: / p>
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?
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?
Thanks!
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.
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];
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
I did like this :
-(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]);
}
}
}
Hope it helps :)
这篇关于使用XMPPFramework为ios存储消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!