【发布时间】: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