iOS 中的 XMPPStreamManagement 无法发送/接收确认和节 ID [英] XMPPStreamManagement in iOS unable to send/receive acknowledgement and stanza id

查看:24
本文介绍了iOS 中的 XMPPStreamManagement 无法发送/接收确认和节 ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能够向用户发送消息,这意味着我有一个有效且经过身份验证的 xmppStream.

I am able to send messages to users which means i have a working and authenticated xmppStream.

但是我无法从服务器发送和接收确认.我想知道服务器成功接收到哪条消息.我用谷歌搜索,发现应该为此实施 XEP-0198.我使用 ejabberd 作为 XMPP 服务器,它支持 XEP-0198.

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.

首先我包含了头文件并添加了 XMPPStreamManagementDelegate.

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];

然后我发消息

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];

测试用户收到消息,测试用户 2 收到收到的节.

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];

我已经实现了以下功能

-(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.

推荐答案

您可以使用 xmppStreamManagement 中的函数发送请求并获取接收 id:

You can use the functions in xmppStreamManagement for sending the request and get received id:

[xmppStreamManagement requestAck];

- (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];

这篇关于iOS 中的 XMPPStreamManagement 无法发送/接收确认和节 ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆