iphone XMPP应用程序运行背景 [英] iphone XMPP App run background

查看:147
本文介绍了iphone XMPP应用程序运行背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用XMPP框架创建了聊天应用程序。当我退出应用程序(进入后台模式)我想接收聊天消息,还需要显示图标徽章...我如何做到这一点? / p>

I created a chat application using XMPP framework..when I quit the app(enter background mode) I want to receive the chat message..and also need to display the icon badge...How can I do this?

推荐答案

您可以通过调用一个VoIP应用程序在iOS4的后台运行基于XMPP框架的应用程序。 ( Apple

You can indeed run a XMPP Framework-based app in the background in iOS4 by calling it a VoIP app. (However, Apple will reject it from the App Store unless it also truly does VoIP).

您需要在应用程序的(appname)-info.plist文件中设置VoIP标志,然后在

You need to set the VoIP flag in your app's (appname)-info.plist file, and then in

(void)xmppStream:(XMPPStream *)sender socketWillConnect:(AsyncSocket *)socket

您需要设置套接字流标记包含 kCFStreamNetworkServiceTypeVoIP

You'll need to set the socket stream flags to include kCFStreamNetworkServiceTypeVoIP:

 CFReadStreamSetProperty([socket getCFReadStream], kCFStreamNetworkServiceType, kCFStreamNetworkServiceTypeVoIP);
 CFWriteStreamSetProperty([socket getCFWriteStream], kCFStreamNetworkServiceType, kCFStreamNetworkServiceTypeVoIP);

然后,当新的XMPP消息到达时,您的应用程序将会被短暂唤醒。在你的正常

Then, your app will be woken up briefly when a new XMPP message arrives. In your normal

(void)xmppStream:(XMPPStream *)sender didReceiveMessage:(XMPPMessage *)message

处理程序,如果您有背景信息,您将需要为消息创建一个本地通知(您可以通过 UIApplicationDidEnterBackgroundNotification UIApplicationWillEnterForegroundNotification )。

handler, you would want to create a local notification for the message if you are backgrounded (you can keep track of background state via UIApplicationDidEnterBackgroundNotification and UIApplicationWillEnterForegroundNotification). The local notification handler can set the application badge number, etc (just like you would for a push notification).

编辑

新版本的XMPP框架(特别是GCDAsyncSocket)现在支持调用以使这更容易,所以你可以只有:

Newer versions of the XMPP Framework (specifically, GCDAsyncSocket) now support a call to make this easier, so you can just have:

- (void)xmppStream:(XMPPStream *)sender socketWillConnect:(GCDAsyncSocket *)socket
{
    // Tell the socket to stay around if the app goes to the background (only works on apps with the VoIP background flag set)
    [socket performBlock:^{
            [socket enableBackgroundingOnSocket];
    }];
}

这篇关于iphone XMPP应用程序运行背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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