如何使用XMPP框架获取消息传递状态 [英] How to get the message delivary status using XMPP framework
问题描述
我正在使用XMPP框架在用户之间聊天,聊天正在发生。现在我需要显示消息是否完美地传递给两个设备,例如(What's app messenger)。我没有得到任何教程可以遵循。下面的代码表示我们向其他用户发送消息。
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];
使用XMPP Framework重新获取消息时,我使用以下代码获取数据
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你需要在connect方法中添加以下代码
@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];
希望这可以帮到你:)
这篇关于如何使用XMPP框架获取消息传递状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!