Ios 应用程序进入后台模式四分钟后播放声音

Ios 应用程序进入后台模式四分钟后播放声音,ios,audio,tvos,Ios,Audio,Tvos,我的应用程序进入后台模式四分钟后如何播放声音 我尝试过使用NSTimer,但它在三分钟后播放,而不是四分钟 func applicationDidEnterBackground(application: UIApplication) { self.timer = NSTimer.scheduledTimerWithTimeInterval(240.0, target: self, selector: "createAVMIDIPlayer", userInfo: nil, repeats

我的应用程序进入后台模式四分钟后如何播放声音

我尝试过使用NSTimer,但它在三分钟后播放,而不是四分钟

func applicationDidEnterBackground(application: UIApplication)
{
    self.timer = NSTimer.scheduledTimerWithTimeInterval(240.0, target: self, selector: "createAVMIDIPlayer", userInfo: nil, repeats: false)
}
func createPlayer() {
    if let soundURL = NSBundle.mainBundle().URLForResource("Text to Speech", withExtension: "m4a") {
        var mySound: SystemSoundID = 0
        AudioServicesCreateSystemSoundID(soundURL, &mySound)
        AudioServicesPlaySystemSound(mySound);
    }
}

通常情况下,iOS应用程序不能在后台播放音频,除非它们在plist中设置了正确的后台模式功能,并且已经开始在前台播放音频(并且没有停止)。

欢迎来到SO,请花点时间拍摄并阅读如何问问题。如果你问了一个非常适合这个网站的问题,你更有可能得到帮助。我正在做一个应用程序。在该应用程序中,当应用程序进入后台时,我希望在4分钟后播放声音编辑您的问题,以清楚地描述问题、您想要实现的结果以及您目前拥有的代码。很简单
NSTimer
不在后台工作。如果你的应用程序在进入后台时没有播放音频,它将被挂起。当你的应用程序进入后台时,你需要播放音频(可能播放无声的音频文件也可以)。由于您没有提供足够的信息,说明我们何时以及如何可能无法帮助您。这里有一个链接,指向一个很好的
delay
函数,非常感谢@matt,因为我经常使用它。。。