在后台运行应用程序时未触发OS X Cocoa计时器 [英] OS X Cocoa timer not fired when application on background

查看:89
本文介绍了在后台运行应用程序时未触发OS X Cocoa计时器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

第三方库提供了我需要每100毫秒调用一次的功能.只要我的应用程序处于前台状态,设置一个计时器就可以很好地工作.当我的应用程序在后台运行时,计时器会工作一会儿,但是大约一分钟后,只有在延迟10秒后才调用计时器.当我使用usleep-function创建一个单独的线程时,也会发生同样的情况.有什么方法可以让我的应用程序在后台运行时保持计时器运行?

A third-party library provides a function I need to call every 100ms. Setting up a timer to do that works very well as long as my app is on foreground. When my app is on background timer works for a while but after a about a minute timer is called only after 10 second delay. The same happened when I created a separate thread with usleep-function. Is there any way I can keep timer running while my app is on background?

推荐答案

使用

Use beginActivityWithOptions:reason: to disable app nap for your application.

这篇关于在后台运行应用程序时未触发OS X Cocoa计时器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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