如何保持iphone的ios XMPP连接活着,而在背景吗? [英] How to keep iphone ios xmpp connection alive while in the background?

查看:250
本文介绍了如何保持iphone的ios XMPP连接活着,而在背景吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关iPhone的XMPPFramework是强大的。我有它运行起来,但你如何保持连接,同时在后台超过10分钟?我想AP preciate一些文件/打开入门指南如何做到这一点。

因此​​,用例是简单而常见的:乔是网上和iPhone聊天应用。他离开聊天应用程序,去野生动物园,玩起了,流的电影,并做其他的东西3小时(或更多)。乔希望保持在这段时间接收消息。

该示例应用程序允许乔在后台接受本地通知,但只有10分钟的它似乎。下面是相关的code(我认为)。谢谢!

要帮助其他人,甚至得到这一点,你需要将xmppstream财产enableBackgroundingSocket为YES(它为你做的iphoneXMPP示例项目,你应该复制)和应用程序的名字,info.plist中(即,iosChat-INFO-的plist)文件,你需要添加一个新的键/值对。你应该右击某个地方添加行。你应该选择的关键所需的背景模式,然后键入网络电话。 X $ C $按c检测您的意思是应用程序提供语音IP服务后,你preSS进入。这可以让你10分钟保持聊天应用程序在后台打开的(我认为)。但我们要无限期的,我怀疑,答案就在下面的方法。我只是认为这种方法什么的,例如内重新连接,[自主连接](我有一个连接方法)?

   - (无效)applicationDidEnterBackground:(UIApplication的*){应用DDLogVerbose(@%@:%@,THIS_FILE,THIS_METHOD);如果([应用respondsToSelector:@selector(setKeepAliveTimeout:处理器:)])
{
    [应用setKeepAliveTimeout:600处理器:^ {        DDLogVerbose(@KeepAliveHandler);        //不要等保活的东西在这里。
    }];
}}


解决方案
还看 [应用beginBackgroundTaskWithExpirationHandler] ,这将允许你
要求更多的时间来完成任务。为了保持连接的100%,你会
需要或者添加网络电话,音频或位置标记的Info.plist(即UIBackgroundModes)。

除非你添加这些标签中的一个一个后台将无法工作。此外,加入标签
可以让你保持联系,但如果您要提交到App Store的实际标记必须是有效的。如果有不是一个真正的用例,苹果将拒绝该应用程序。

要保持更长的连接没有标签,你将需要诉诸使用某种类型的服务器,它保持连接,然后使用推送通知邮件传递。

The XMPPFramework for iPhone is powerful. I have it up and running, but how do you keep the connection alive while in the background for more than 10 minutes? I would appreciate some more documentation/how-tos on how to accomplish this.

So the use case is simple and common: Joe is online and in the iPhone chat app. He leave the chat app and goes to Safari, plays a game, streams a movie, and does other stuff for 3 hours (or more). Joe wants to keep receiving messages during that time.

The example app allows Joe to receive local notifications in the background, but for only 10 minutes it seems. Here's the relevant code (I think). Thanks!

To help out other folks, to even get to this point, you need to the xmppstream property enableBackgroundingSocket to YES (it's done for you in the iphoneXMPP example project which you should copy) and in the appname-info.plist (i.e., iosChat-info-plist) file you need to add a new key/value pair. You should right click somewhere and "add row". You should choose for the key "required background modes" and then type in "voip". Xcode will detect that you mean "App provides Voice over IP services" after you press enter. This gets you 10 minutes of keeping the chat app open in the background (I think). But we want indefinitely, and I suspect that the answer lies in the method below. Am I just supposed to "reconnect" within this method or something,e.g., [self connect] (I have a connect 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.
    }];
}}

解决方案

10 minutes is the approximate time iOS allows you to stay connected. You can also look at [app beginBackgroundTaskWithExpirationHandler], which will allow you to request more time to finish a task. In order to remain connected 100%, you will need to either add a voip, audio or location tag to info.plist (that is UIBackgroundModes).

Backgrounding will not work unless you add one of those tags. In addition, adding a tag will allow you to remain connected, but the actual tag must be valid if you're submitting to the App Store. Apple will reject the app if there's not a real use-case.

To remain connected longer without a tag, you will need to resort to using some type of server, which maintains the connection and then uses push notifications to deliver messages.

这篇关于如何保持iphone的ios XMPP连接活着,而在背景吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆