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

标签 ios xmpp openfire

我正在构建一个基于 XMPP 的 iOS 应用程序。当我通过 XMPPFramework 从客户端发送 XMPP 消息时,我发现委托(delegate)的消息立即被调用。

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

但是我的消息包含很多数据,我肯定不能这么快发送。然后用户将应用程序置于后台,消息丢失。我怎么解决这个问题?

最佳答案

好像是

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

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

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

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

Apple 文档: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

关于ios - 如何保证XMPP消息发送到openfire服务器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10228625/

相关文章:

authentication - 如何使用 JWT token 而不是用户名、密码对 Openfire XMPP 进行身份验证

iOS:将文件从 Office 应用复制到我的应用的文档

iphone - 如何从用户定义的对象中提取 NSString?

ios - 在 iOS 上通过 websocket 连接到 XMPP?

xmpp - 如何在 XMPP ejabberd 服务器中使用 Rosters 访问所有用户

java - 如何在smack中获取当前用户的名字

c# - XMPP - Openfire SSL 加密 - 从哪里开始?

ios - AVMutableAudioMixInputParameters 未正确应用于 AudioMiX

ios - 错误 ITMS-9000 无效架构 x86_64、i386

ios - 如何在 iOS 上使用 XMPPFramework 和 OpeFire 创建/更新/检索用户 vCard