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

标签 ios audio tvos

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

我尝试使用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中设置了正确的背景模式功能,并且已经开始在前台播放音频(并且没有停止播放),否则它们无法在后台播放音频。

关于ios - 应用进入后台模式四分钟后播放声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35066797/

相关文章:

ios - 使用 swift 我们可以以编程方式在 Apple TV 上播放照片吗?

ios - iOS swift 中的集成

ios - 使用户仅在完成操作 IOS Swift 3 后才访问 View

swift - 使用NSTimer按设定的时间间隔播放声音,在后台不工作Xcode6.4

javascript - 检测 HTML5 音频元素文件未找到错误

delphi - 使用 Delphi 7 从 MP3 文件中删除或编辑 ID3Tag 版本 2

ios - 在 iOS 应用程序中使用具有不同目标的不同 Assets.xcassets?

ios - 崩溃-setImageWithURLRequest :~

swift - 在 tvos 中更改焦点时如何关闭 UISearchController 中的键盘?

swift - tvOS 上的 UISplitViewController - 禁用滑动到详细 View Controller