简体   繁体   中英

Does iOS 4 make “Real Multitasking” available to 3rd party developers?

Ever since the first beta came out I've been trying to find out if “real” multitasking is possible — ie can you put a program in the background and have it hang on to a network connection indefinitely?

I'm thinking about IM or IRC apps, for example. I've compiled an app myself on iOS 4, and without changing a thing it appeared to stay running in the background, but for all I know it was just suspended to memory.

The docs say the best you can do is request up to 10 minutes, but in the developer presentation they showed off Skype sitting in the background and then notifying the user that a call was coming in. Does anyone know for sure how this all works?

It appears the answer is no. The API for Skype is a very special case, called the "voip" mode, and requires special behavior, such as marking the socket in use for VoIP.

You can receive alarm notifications in the background (such as time passed). The amount of time you are in the background running state is severely limited by the OS.

Android's background model is complete and in many ways much nicer.

Apple has a guide named "Supporting Multitasking In Your Applications" which you should be able to locate.

Apple's iOS 4 developer docs outline this all very clearly.

When your app is closed or switched away from, it is almost immediately "suspended", meaning the OS freezes the app's state. When the user switches back to your app, your code keeps running just where it kept off. You don't need to add any code to your app to do this, just compile it against OS 4.

The above is true in most cases. There are two reasons the "suspended" model may not apply:

1) If the device starts to run low on memory, the OS will start terminating suspended apps that haven't been switched to in a while, without warning. This is why it's in your best interest for your app to remember it's state as well, so if your app is terminated, then re-opened, the user doesn't really notice because it still returns to right where they left off.

2) Your app uses one of the "background" APIs. These are for audio playback, VoIP services, or location services. In this case, your app is allowed to continue running in the background but only has access to those APIs. Additionally, your app can designate certain long-running tasks as "background tasks" that need to be completed before the app is suspended or terminated, like uploading pictures to Flickr or rendering a video, etc.

The "background task" method doesn't cover pinging servers indefinitely, as there is a time limit for the task, after which it will be forcibly halted. Apps that need that sort of functionality are expected to implement push notifications, just as before.

That should clear this up. All in all I think it's a pretty elegant solution to multitasking on a mobile device.

iOS 4 applications can either be running or suspended . The operating system will try to keep as many requested applications as possible in memory, while all other applications are suspended.

Applications that run in the background can access features such as navigation, audio, and VOIP (but NOT instant messaging). So it looks like you might be out of luck.

-- PC World Multitasking on Apples iPhone 4

It is possible for apps to request background time. Read the docs. I would say it iOS is "controlled multitasking".

You can create a long running background task, I believe these can include networking features. Just have to set the background task flag on the work block.

https://developer.apple.com/iphone/library/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/BackgroundExecution/BackgroundExecution.html

the OS can limit exactly how much time you get though... it will tell you when your time is up giving you a chance to cleanup nicely.

iOS 4 has "real" multitasking to some extend. There are two things to consider:

  • The UI event loop is single tasking. So only the front app executes on the UI event loop. Not a big deal: detach your main code form the UI event loop (maybe you need to redesign your app).
  • The OS "may" terminate your app if some criteria are met (eg low memory).

Currently one of these criteria is that execution time is limited to 10 minutes (real time not cpu time). However I expect this to change and see better criteria for background app termination (I hope to).

Apart from this you can have timers (event loops) in background .

There is no real multitasking in iOS 4.2 even. because apps will only be allowed to finish the task related to states..for small interval of time and then it will be in suspended state.. If you will set background task for long interval of time then... it will behave unexpectedly like no method will be called when you will try to run the app from anywhere..

您可能对此博客文章感兴趣, 该博文概述了“多任务处理”如何在iPhone OS 4和Android等系统中运行。

in fact u can do this, although it's not allowed by Apple. u gotta set up a toolchain in ur mac and use some unofficial SDK...

check http://code.google.com/p/iphone-backgrounder/ for more information

您应该使用Push Notifications框架来创建您正在创建的功能集!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM