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?
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- Could I create “Call” button in HTML 5 IPhone appl
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- xcode 4 garbage collection removed?
- Xcode: Is there a way to change line spacing (UI L
- Unable to process app at this time due to a genera
There are a limited number of programs that can run in the background without limit, these being VOIP programs, those that play music, and those that track the user's location. If you're not doing any of these legitimately then you're limited to ten minutes of background operation. Note that Apple will reject apps that try silly tricks like playing 'empty' sounds to keep the app live.
You can find info on running tasks in the background here: http://developer.apple.com/library/ios/#documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html
Your other option I would guess is to have the chat program operate by contacting a server, and to have that server queue responses when a user is offline then deliver them when they next log on. Not being a net programmer myself I don't know how feasible this is, but I think it's the only way to do this indefinitely if you're only offering text chat. The better option would be to make your application VOIP enabled using the guide above.
EDIT As of the release of iOS 5.0, it is also possible to get apps registered as Newsstand applications to download information while backgrounded, plus a bunch of other funky features that are also Newsstand only.
-Ash
In the latest XMPP Framework you don't need to modify framework files.
Just do this: 1. Add this to your connect method
2. Add voip key to your info plist file:
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).
You need to set the VoIP flag in your app's (appname)-info.plist file, and then in
You'll need to set the socket stream flags to include
kCFStreamNetworkServiceTypeVoIP
:Then, your app will be woken up briefly when a new XMPP message arrives. In your normal
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
andUIApplicationWillEnterForegroundNotification
). The local notification handler can set the application badge number, etc (just like you would for a push notification).EDIT
Newer versions of the XMPP Framework (specifically, GCDAsyncSocket) now support a call to make this easier, so you can just have: