一段时间后,NSTimer在后台停止 [英] NSTimer stops in the background after some time

查看:252
本文介绍了一段时间后,NSTimer在后台停止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当应用程序进入后台并且在将近17分钟后计时器停止工作时,我使用NSTimer在1秒后调用方法。

I used NSTimer to call a method after 1 sec when app goes in background and after nearly 17 minutes timer stops working.

当它回到正面时它再次开始工作,所以请告诉我为什么会发生这种情况以及如何解决问题。

When it came back in the foregound it again started working, so please tell me why this is happening and how to resolve the issue.

为了同样的目的,我也尝试使用延迟递归的执行选择器,但是再次给出相同的结果。请建议任何解决方案。任何帮助都将完全受到赞赏。

I also tried using perform selector with delay in recursion for the same purpose, but again giving the same result. Please suggest any solution. Any help will be completely appreciated.

推荐答案

Wierd问题 - 我也有这个问题,但以下内容对我有用。

Wierd issue- i too had this one, but the following worked for me.

 //Run the timer on the runloop to ensure that it works when app is in background

  [[NSRunLoop currentRunLoop]addTimer:self.timer forMode: NSDefaultRunLoopMode];

这篇关于一段时间后,NSTimer在后台停止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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