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


如何在

应用进入后台模式四分钟后播放声音?

我尝试过使用 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 中设置了正确的背景模式功能,并且已经开始在前台播放音频(并且尚未停止)。

最新更新