如何保证 XMPP 消息发送到 openfire 服务器?

Posted

技术标签:

【中文标题】如何保证 XMPP 消息发送到 openfire 服务器?【英文标题】:How to ensure the XMPP message sent to the openfire server? 【发布时间】:2012-04-19 12:58:55 【问题描述】:

我正在构建一个基于 XMPP 的 ios 应用。当我通过 XMPPFramework 从客户端发送 XMPP 消息时,我发现代理的消息立即被调用。

- (void)xmppStream:(XMPPStream *)sender didSendMessage:(XMPPMessage *)message

但我的信息包含大量数据,我确信它不能发送得这么快。然后用户将应用程序置于后台,消息丢失。我怎么解决这个问题?

【问题讨论】:

【参考方案1】:

好像

- (void)xmppStream:(XMPPStream *)sender didSendMessage:(XMPPMessage *)message;

被立即调用,是的,但是:

如果您的应用程序已进入后台状态,您最多可以请求 10 分钟的时间,以确保您的请求完成:

关于背景的文章说:http://www.macworld.com/article/1164616/how_ios_multitasking_really_works.html

苹果文档:http://developer.apple.com/library/ios/#DOCUMENTATION/iPhone/Conceptual/iPhoneOSProgrammingGuide/ManagingYourApplicationsFlow/ManagingYourApplicationsFlow.html

XMPPStream 有一个属性 enableBackgroundingOnSocket,您可以将其设置为 YES:

/**
 * If set, the kCFStreamNetworkServiceTypeVoIP flags will be set on the underlying CFRead/Write streams.
 * 
 * The default value is NO.
**/
@property (readwrite, assign) BOOL enableBackgroundingOnSocket;

请注意,在使用此技巧“伪造”此处讨论的 voip 后台模式时,您可能会遇到 App Store 问题:

iphone XMPP App run background

【讨论】:

以上是关于如何保证 XMPP 消息发送到 openfire 服务器?的主要内容,如果未能解决你的问题,请参考以下文章