OS X Cocoa timer not fired when application on background

…衆ロ難τιáo~ 提交于 2019-12-07 14:32:56

问题


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?


回答1:


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




回答2:


You should try and re-architect to avoid these sorts of frequent timers, especially when your application is in the background. Making this sort of change will improve battery life for your users.



来源:https://stackoverflow.com/questions/20607290/os-x-cocoa-timer-not-fired-when-application-on-background

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!