如何在后台运行NSTimer和睡眠在iOS? [英] How to run NSTimer in background and sleep in iOS?
本文介绍了如何在后台运行NSTimer和睡眠在iOS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在stackoverflow中发现了很多关于 NSTimer
在后台运行的帖子。
I found a lot of post in stackoverflow about NSTimer
run in background.
找到任何解决方案。
在我的应用程序中,我在后台播放声音,我设置计时器,当到达时间停止音乐。
In my app , I play sound in background and I set timer to stop music when it reached that time.
所以我需要运行我的 NSTimer
背景(当主页按钮点击并睡觉iPhone时)。
So I need to run my NSTimer
background (mean when home button click and sleep iPhone).
我如何做?
推荐答案
// NSTimer run when app in background <br>
[[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:nil];
loop = [NSTimer scheduledTimerWithTimeInterval:0.25 target:self selector:@selector(Update) userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:loop forMode:NSRunLoopCommonModes];
这是你想要什么?
这篇关于如何在后台运行NSTimer和睡眠在iOS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文