Iam*_*yne 4 nsnotifications avaudioplayer avaudiosession swift swift4
尝试处理项目中的音频中断。
该代码曾经在Swift 4中运行。
NotificationCenter.default.addObserver(self, selector: #selector(handleInterruption(_:)), name: NSNotification.Name.AVAudioSessionInterruption, object: nil)
Run Code Online (Sandbox Code Playgroud)
自从更新到Swift 4.2之后,它给了我建议更改为
NotificationCenter.default.addObserver(self, selector: #selector(handleInterruption(_:)), name: Notification.Name.AVAudioSession.interruptionNotification, object: nil)
Run Code Online (Sandbox Code Playgroud)
更改为建议的修复程序后,我得到了错误: 类型'Notification.Name'(aka'NSNotification.Name')没有成员'AVAudioSession'
任何帮助,将不胜感激。
使用的文件:
func setupNotifications() {
let notificationCenter = NotificationCenter.default
notificationCenter.addObserver(self, selector: #selector(handleInterruption), name: .AVAudioSessionInterruption, object: nil)
Run Code Online (Sandbox Code Playgroud)
}
但是该文档并未针对Swift 4.2进行更新。
Xcode迁移器工具中存在错误。正确的解决方法是
NotificationCenter.default.addObserver(self, selector: #selector(handleInterruption(_:)), name: AVAudioSession.interruptionNotification, object: nil)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
577 次 |
| 最近记录: |