注意:服务器已安装并正在运行流管理。
这是我的代码:
XMPPStreamManagementMemoryStorage *storage1=[[XMPPStreamManagementMemoryStorage alloc] init];
xmppStreamManagement=[[XMPPStreamManagement alloc] initWithStorage:storage1];
xmppStreamManagement.autoResume = YES;
[xmppStreamManagement enableStreamManagementWithResumption:TRUE maxTimeout:5];
[xmppStreamManagement addDelegate:self delegateQueue:dispatch_get_main_queue()];
[xmppStreamManagement activate:xmppStream];
[xmppStreamManagement requestAck];
我也实现了委托方法。 但我既没有在委托方法中得到回应,也没有看到流管理工作。
它将如何运作以及我们如何验证它?
在这里,如果我在iOS端成功实现了流管理,那么就会自动丢失离线消息
- (void)xmppStream:(XMPPStream *)sender didReceiveMessage:(XMPPMessage *)message
任何帮助将不胜感激。
答案 0 :(得分:2)
在iOS应用中启用XMPPStreamManagement
非常容易。
使用XMPPStreamManagement
初始化您的XMPPStreamManagementMemoryStorage
个实例。
XMPPStreamManagementMemoryStorage *xmppSMMS = [[XMPPStreamManagementMemoryStorage alloc] init];
xmppStreamManagement = [[XMPPStreamManagement alloc] initWithStorage:xmppSMMS];
将您的实现类添加为其委托
[xmppStreamManagement addDelegate:self delegateQueue:dispatch_get_main_queue()];
现在,在连接XMPPStream
并进行绑定后启用流管理。
[xmppStreamManagement activate:xmppStream];
xmppStreamManagement.autoResume = YES;
[xmppStreamManagement enableStreamManagementWithResumption:YES maxTimeout:0];
[xmppStreamManagement requestAck];
实施委托方法
- (void)xmppStreamManagement:(XMPPStreamManagement *)sender wasEnabled:(NSXMLElement *)enabled{
}
- (void)xmppStreamManagement:(XMPPStreamManagement *)sender wasNotEnabled:(NSXMLElement *)failed{
}
- (void)xmppStreamManagement:(XMPPStreamManagement *)sender didReceiveAckForStanzaIds:(NSArray *)stanzaIds{
}
答案 1 :(得分:2)
身份验证成功后,调用流管理。
也不要忘记调用'sendAck()'方法。
// Stream Management
let xmppSMMS = XMPPStreamManagementMemoryStorage()
xmppStreamManagement = XMPPStreamManagement(storage: xmppSMMS, dispatchQueue: DispatchQueue.main)
xmppStreamManagement.addDelegate(self, delegateQueue: DispatchQueue.main)
xmppStreamManagement.activate(xmppStream)
xmppStreamManagement.autoResume = true
xmppStreamManagement.ackResponseDelay = 0.2
xmppStreamManagement.requestAck()
xmppStreamManagement.automaticallyRequestAcks(afterStanzaCount: 1, orTimeout: 10)
xmppStreamManagement.automaticallySendAcks(afterStanzaCount: 1, orTimeout: 10)
xmppStreamManagement.enable(withResumption: true, maxTimeout: 0)
xmppStreamManagement.sendAck()
xmppStream.register(xmppStreamManagement)