iPhone equivalent to Android's services
I'm going to port my app from Android to iPhone.
My Android version uses 2 services, one for updating from server (http requests) and store in local DB and another for monitoring some things (alarms).
How could I implement a similiar functionality in iPhone?. Do I need to start 2 threads from main and thats all? or does it have a similar functionality?.
And in the same question. Can I make http calls from my sync thread (or 开发者_开发问答whatever) while my app is not in the user focus?
I'm not very familiar with Android development, but I think I may be able to help.
As far as running HTTP Requests, you can obviously do that. I recommend the third party library ASIHTTPRequest for that. This library is very flexible and can help simplify the requests.
For local storage, you have a few options. You can use Core Data (which is the closest thing to a database, short of SQLite) or NSUserDefaults, depending on what you want to store. You can also use NSKeyedArchiver to write objects to disk as files.
As far as making HTTPRequests in the background, this is limited by certain factors. See this document for more information. Basically, your app can request up to ten minutes of background time, after which it must stop.
Second point;
Till your application is alive (whether it is active or running in background) you can make http calls through both main or sub threads. You need to set whether your application will keep running in background mode.
http://developer.apple.com/library/ios/#documentation/iphone/conceptual/iphoneosprogrammingguide/BackgroundExecution/BackgroundExecution.html
精彩评论