I am using the XMPP Framework for chatting between the users , Chatting is happening perfectly .Now I need to show the message is delivered perfectly to both devices like (What's app messenger). I am not getting any tutorial to follow. Below code represents while we send message to the other user.
//Sending the message to the other user
NSXMLElement *body = [NSXMLElement elementWithName:@"body"];
[body setStringValue:txtChat.text];
NSXMLElement *message = [NSXMLElement elementWithName:@"message"];
[message addAttributeWithName:@"type" stringValue:@"chat"];
[message addAttributeWithName:@"to" stringValue:self.userjid];
[message addChild:body];
[[APPDELEGATE xmppStream] sendElement:message];
While reterving the message by using XMPP Framework i was getting the data by using below code
- (void)loadarchivemsg
{
XMPPMessageArchivingCoreDataStorage *storage = [XMPPMessageArchivingCoreDataStorage sharedInstance];
NSManagedObjectContext *moc = [storage mainThreadManagedObjectContext];
NSEntityDescription *entityDescription = [NSEntityDescription entityForName:@"XMPPMessageArchiving_Message_CoreDataObject"
inManagedObjectContext:moc];
NSFetchRequest *request = [[NSFetchRequest alloc]init];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(bareJidStr like %@) && (streamBareJidStr like %@)", self.userjid,[[NSUserDefaults standardUserDefaults] stringForKey:@"kXMPPmyJID"]];
request.predicate = predicate;
NSLog(@"%@",[[NSUserDefaults standardUserDefaults] stringForKey:@"kXMPPmyJID"]);
[request setEntity:entityDescription];
NSError *error;
NSArray *messages_arc = [moc executeFetchRequest:request error:&error];
[self print:[[NSMutableArray alloc]initWithArray:messages_arc]];
}
- (void)print:(NSMutableArray*)messages_arc{
@autoreleasepool {
for (XMPPMessageArchiving_Message_CoreDataObject *message in messages_arc) {
NSXMLElement *element = [[NSXMLElement alloc] initWithXMLString:message.messageStr error:nil];
XMPPMessage *message12=[[XMPPMessage alloc]init];
message12 = [message message];
}
}
In this why I was sending the message and retrieving the message,can you help me how to retrieve the delivery status of the message . Waiting for your valuable answers.
@Romance you need to add below code in the connect method
XMPPMessageDeliveryReceipts* xmppMessageDeliveryRecipts = [[XMPPMessageDeliveryReceipts alloc] initWithDispatchQueue:dispatch_get_main_queue()];
xmppMessageDeliveryRecipts.autoSendMessageDeliveryReceipts = YES;
xmppMessageDeliveryRecipts.autoSendMessageDeliveryRequests = YES;
[xmppMessageDeliveryRecipts activate:self.xmppStream];
Remember to add these line while sending message
NSString *messageID=[self.xmppStream generateUUID];
NSXMLElement *message = [NSXMLElement elementWithName:@"message"];
[message addAttributeWithName:@"id" stringValue:messageID];
[message addAttributeWithName:@"type" stringValue:@"chat"];
[message addAttributeWithName:@"to" stringValue:[NSString stringWithFormat:@"senderJabberID_Here"]];
[message addChild:body];
Hope this help you :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With