应用程序后台运行时,NSTimer是否会启动? [英] Is NSTimer expected to fire when app is backgrounded?

查看:75
本文介绍了应用程序后台运行时,NSTimer是否会启动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一点也不了解,但是我的应用程序中的NSTimer肯定在后台运行.我在计时器运行的方法中有一个NSLog,它在后台时正在记录日志.在装有iOS 4.2.1的iPhone 4上.我已经在Info.plist中声明了位置背景支持.

I don't understand it at all but NSTimer in my app definitely is running in background. I have a NSLog in method run by the timer and it is logging while it's in background. It's on iPhone 4 with iOS 4.2.1. I have declared location background support in Info.plist.

我在这里和其他地方阅读了文档和许多讨论,这是不可能的.是iOS的错误吗?还是未记录的功能?我不想使用它并在不久的将来发现它,例如,随着iOS 4.3的到来,Apple默默地修复"了它,该应用程序将无法正常工作.

I read the docs and many discussions here and elsewhere and it shouldn't be possible. Is it an iOS bug? Or undocumented feature? I don't want to use it and find out in near future, for example with coming of iOS 4.3 that Apple silently "fixed" it and the app won't be working.

有人知道吗?

推荐答案

NSTimer将在主运行循环运行时触发.苹果不承诺取消计时器安排或阻止主运行循环运行.当您移至后台时,您有责任取消计划计时器并释放资源.苹果不会为您做到这一点.但是,如果您不应该使用它们或花太多时间,它们可能会杀死您的跑步.

NSTimer is going to fire whenever the main runloop is running. Apple makes no promises that I know of to unschedule timers or to prevent the main runloop from running. It's your responsibility to unschedule your timers and release resources when you move to the background. Apple isn't going to do it for you. They may, however, kill you for running when you are not supposed to or using too many seconds.

系统中存在许多漏洞,这些漏洞将允许应用程序在未经授权的情况下运行.防止这种情况对于OS而言将是非常昂贵的.但是你不能依靠它.

There are many holes in the system that will allow an app to run when it isn't authorized to. It would be very expensive for the OS to prevent this. But you cannot rely on it.

这篇关于应用程序后台运行时,NSTimer是否会启动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆