【问题标题】:How to handle Siri interruption on Apple TV如何处理 Apple TV 上的 Siri 中断
【发布时间】:2026-01-24 05:50:01
【问题描述】:

我正在寻找一种方法来处理 AppleTV 上的 Siri 中断。

根据本指南:https://developer.apple.com/documentation/avfoundation/avaudiosession/responding_to_audio_session_interruptions 应该可以获得音频会话中断的通知,但这似乎不起作用。

我试过了

NotificationCenter.default.addObserver(
        self,
        selector: #selector(handleInterruption(_:)),
        name: .AVAudioSessionInterruption,
        object: nil)

回调永远不会发生。

我想要的是在用户使用 Siri 时暂停视频,然后在他们完成后继续播放。

【问题讨论】:

    标签: tvos siri


    【解决方案1】:
    internal func registerToHandleInterruptions() {
        // When Siri interrupts playback a UIApplicationWillResignActive notification will be triggered
        NotificationCenter.default.addObserver(
            self,
            selector: #selector(handleInterruption(_:)),
            name: .UIApplicationWillResignActive,
            object: nil)
        // When Siri returns control to the app, a UIApplicationDidBecomeActive notification is fired
        NotificationCenter.default.addObserver(
            self,
            selector: #selector(handleActive(_:)),
            name: .UIApplicationDidBecomeActive,
            object: nil)
    }
    

    经过大量搜索,我发现了以下内容:

    • 在 tvOS 上,Siri 中断似乎不会触发 .AVAudioSessionInterruption 通知,尽管官方文档说了什么。 (过时了?,不适用于 tvOS?)

    • Siri 中断实际上是将应用程序发送到后台,因此可以通过观看 .UIApplicationWillResignActive.UIApplicationDidBecomeActive 来做出反应。

    【讨论】: