IOS task completion API abuse

Source: Internet
Author: User
Tags home screen

As defined of you are aware, ios4 introduced several APIs that bring some degree of multitasking to iOS applications: one of them was originally meant to give an App the extra chance to finish some worthy tasks before getting susponded: It's called "task completion
API ".

Unfortunately this API has become a free ticket for up to 10 minutes of background execution that every app can get, even the ones that don't need it.

This means some apps may ask for extra CPU time and remain in background execution for as long as 10 minutes (the limit set by the IOS ).
The problem is that we have no quick way of telling wether this extra time is being used for the completion of a useful task or if it is being abused.

With the help of the "instruments" application written with xcode I 've tried to analyze the behavior of a few common apps and noticed that task completion abuse actually happens with at least two very popular titles: "WhatsApp messenger" and "Facebook Messenger ".

Instruments 'activity monitor shows how regular IOS apps like Twitter and Foursquare are susponded by the OS a few seconds after returning to the home screen.
WhatsApp and Fb messenger instead ask for extra background CPU time in order to wait for incoming chat messages. after the 10 minutes period expires the apps are suincluded and therefore switch to the push into icaiton API to receive incoming messages.
While this behavior may seem harmless it is actually preventing the CPU from sleeping and drains a considerable amount of battery. in fact, even if the apps aren't doing much work, their used CPU time keeps increasing at a slow albeit constant pace.

Yes it's true that after 10 minutes these apps will be susponded anyway and the CPU may then sleep, but only if we aren't using them in the meantime!
For example, say we send a chat message, lock the phone and wait for 9 minutes, then we send another message, lock the phone and wait for another 9 minutes and so on... Our messaging application will use the task completion API each time and therefore will never
Be susponded because it is brought back to the foreground before its 10 minutes extra time expires.

Suincluded apps aren't allocated any CPU time thereby increasing the chances the CPU has to go to its sleep state: In an ideal scenario, the 9 minutes between each chat message wowould have been all eligible for the CPU to sleep!

I think the developers of these applications shoshould rethink about their design choices and avoid using the task comlpetion API because it doesn' t fit in this special use case. the traditional push notification API shoshould be always preferred instead.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.