Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
230 views
in Technique[技术] by (71.8m points)

ios - How to get the message delivary status using XMPP framework

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

@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 :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...