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 :)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…