问题
I am able to send messages to users which means i have a working and authenticated xmppStream.
But i am unable to send and receive acknowledgement from server. I want to know which message was received successfully by the server. I googled and found that XEP-0198 should be implemented for this. I am using ejabberd as XMPP server and it supports XEP-0198.
I tried that but i don't know if i am doing it right or not.
First of all i included the header file and added XMPPStreamManagementDelegate.
#import "XMPPStreamManagement.h"
@interface AppDelegate : UIResponder <UIApplicationDelegate,XMPPStreamManagementDelegate>
In the implementation file, here's how i have defined the stream.
XMPPStream *xmppS = [[XMPPStream alloc] init];
[xmppS addDelegate:self delegateQueue:dispatch_get_main_queue()];
XMPPStreamManagement *xsm = [[XMPPStreamManagement alloc] init];
[xsm addDelegate:self delegateQueue:dispatch_get_main_queue()];
[xsm activate:xmppS];
After that i connect with the server. After the connection is successful, i send an enable stanza.
NSXMLElement *enable = [NSXMLElement elementWithName:@"enable" xmlns:@"urn:xmpp:sm:3"];
[xsm.xmppStream sendElement:enable];
Then i send a message
NSXMLElement *a = [NSXMLElement elementWithName:@"request" xmlns:@"urn:xmpp:receipts"];
XMPPElement *e = [[XMPPElement alloc] initWithName:@"message"];
[e addAttributeWithName:@"id" stringValue:@"123456"];
[e addAttributeWithName:@"type" stringValue:@"chat"];
[e addAttributeWithName:@"to" stringValue:@"testuser@myxmppserver.com"];
[e addAttributeWithName:@"from" stringValue:@"testuser2@myxmppserver.com"];
[e addChild:a];
[xsm.xmppStream sendElement:e];
Test User receives the message and Test User 2 gets the received stanza.
<received xmlns="urn:xmpp:receipts" id="123456"/>
My problem is if i send the following stanza, i receive no message.
NSXMLElement *r = [NSXMLElement elementWithName:@"r"];
[xsm.xmppStream sendElement:r];
I have implemented the following function
-(void)xmppStreamManagementDidRequestAck:(XMPPStreamManagement *)sender
{
NSLog(@"ACK");
}
But still nothing gets printed. Please help. Also, how can i know when the server has received the sent message.
Let me know if anyone wants to know any other part of code from my side.
回答1:
You can use the functions in xmppStreamManagement for sending the request and get received id:
[xmppStreamManagement requestAck];
and
- (void)xmppStreamManagement:(XMPPStreamManagement *)sender wasEnabled:(NSXMLElement *)enabled
- (void)xmppStreamManagement:(XMPPStreamManagement *)sender didReceiveAckForStanzaIds:(NSArray *)stanzaIds
make sure the stream management is enabled by:
[self.xmppStreamManagement enableStreamManagementWithResumption:YES maxTimeout:0];
来源:https://stackoverflow.com/questions/28615170/xmppstreammanagement-in-ios-unable-to-send-receive-acknowledgement-and-stanza-id