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

查看:22
本文介绍了当应用程序后台运行时,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 将在主 runloop 运行时触发.据我所知,Apple 没有做出任何取消计划计时器或阻止主运行循环运行的承诺.当您移动到后台时,您有责任取消安排您的计时器并释放资源.苹果不会为你做这件事.但是,它们可能会因为你不应该跑步或使用太多秒而杀死你.

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.

系统中有许多漏洞允许应用在未经授权的情况下运行.操作系统要防止这种情况会非常昂贵.但你不能依赖它.

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天全站免登陆