How to keep iphone ios xmpp communication in background?

XMPPFramework for iPhone is powerful. Everything works for me, but how to keep the connection in the background for more than 10 minutes? I would appreciate additional documentation / instructions on how to do this.

So, the use case is simple and common: Joe online and in the iPhone app. He leaves the chat application and goes to Safari, plays the game, broadcasts the movie and does other things for 3 hours (or more). Joe wants to continue to receive messages during this time.

The sample application allows Joe to receive local notifications in the background, but only 10 minutes. Here is the relevant code (I think). Thanks!

To help other people even get to this, you need the xmppstream enableBackgroundingSocket property for YES (this is done for you in the iphoneXMPP example project that you must copy) and in appname-info.plist (i.e., iosChat-info-plist ) you need to add a new key / value pair. You must right-click and "add row". You must select “required background modes” for the key, and then enter “voip”. Xcode will detect that you mean that the “application provides voice over IP services” after pressing the enter key. This will make you 10 minutes to keep the chat application open in the background (I think). But we want endlessly, and I suspect that the answer lies in the method below. Do I just have to "reconnect" to this method or something else like [self connect] (do I have a connection method)?

- (void)applicationDidEnterBackground:(UIApplication *)application{ DDLogVerbose(@"%@: %@", THIS_FILE, THIS_METHOD); if ([application respondsToSelector:@selector(setKeepAliveTimeout:handler:)]) { [application setKeepAliveTimeout:600 handler:^{ DDLogVerbose(@"KeepAliveHandler"); // Do other keep alive stuff here. }]; }} 
+2
ios iphone background connection xmpp
source share
1 answer

10 minutes is an approximate time when iOS allows you to stay connected. You can also watch [app beginBackgroundTaskWithExpirationHandler] , which will allow you to request more time to complete the task. To stay in touch 100%, you must either add a voip, audio or location tag to info.plist (this is UIBackgroundModes).

The background image will not work unless you add one of these tags. In addition, adding a tag will allow you to stay connected, but the actual tag must be valid if you submit to the App Store. Apple will reject the application if there is no real use case.

To stay in touch longer without a tag, you need to resort to using some server that supports the connection, and then uses push notifications to deliver messages.

+3
source share

All Articles