【问题标题】:AVAudio session interruptionAV录音中断
【发布时间】:2018-10-03 16:59:59
【问题描述】:

尝试在我的项目中处理音频中断。

这段代码曾经在 swift 4 中工作过。

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

自从更新到 Swift 4.2 后,它给了我更改为

的建议
NotificationCenter.default.addObserver(self, selector: #selector(handleInterruption(_:)), name: Notification.Name.AVAudioSession.interruptionNotification, object: nil)

更改为建议的修复后,我收到错误: 类型“Notification.Name”(又名“NSNotification.Name”)没有成员“AVAudioSession”

任何帮助将不胜感激。

使用的文件:

func setupNotifications() {
let notificationCenter = NotificationCenter.default
notificationCenter.addObserver(self, selector: #selector(handleInterruption), name: .AVAudioSessionInterruption, object: nil)

}

但该文档并未针对 swift 4.2 进行更新。

【问题讨论】:

    标签: swift swift4 avaudioplayer avaudiosession nsnotifications


    【解决方案1】:

    Xcode 迁移器工具中存在错误。正确的解决方法是,

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

    【讨论】:

    • 我们需要为此移除观察者吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-19
    • 2012-10-10
    • 1970-01-01
    • 2014-10-30
    • 1970-01-01
    • 2021-08-05
    相关资源
    最近更新 更多