1

I am building an iOS app based on XMPP. When I send an XMPP message from a client via XMPPFramework, I found the message of the delegate called instantly.

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

But my message contains lots of data, I am sure it cannot be sent so fast. Then the user puts the app to background, and the message is lost. How can I solve this problem?

JoseK
  • 31,141
  • 14
  • 104
  • 131

1 Answers1

0

It seems that

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

is called instantly, true, but:

You can request up to 10 minutes of time if your application has entered background state to ensure that your request finishes:

Article about the background states: http://www.macworld.com/article/1164616/how_ios_multitasking_really_works.html

Apple Docs: http://developer.apple.com/library/ios/#DOCUMENTATION/iPhone/Conceptual/iPhoneOSProgrammingGuide/ManagingYourApplicationsFlow/ManagingYourApplicationsFlow.html

The XMPPStream has a property enableBackgroundingOnSocket which you can set to 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;

Note that you can run into issues with the App Store, when using this trick to "fake" the voip background mode as discussed here:

iphone XMPP App run background

Community
  • 1
  • 1
lars
  • 239
  • 2
  • 9