iOS Task Completion API abuse

As many 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 suspended: 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 included 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 suspended 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 suspended and therefore switch to the Push Notificaiton 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 suspended 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 suspended because it is brought back to the foreground before its 10 minutes extra time expires.

Suspended 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 would have been all eligible for the CPU to sleep!

I think the developers of these applications should rethink about their design choices and avoid using the Task Comlpetion API because it doesn’t fit in this particular use case. The traditional Push Notification API should be always preferred instead.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值