Swift 3中的AVAudiosessionInterruptionNotification

Kal*_*uni 4 xcode ios swift swift2 swift3

这是我在swift 2中的代码.

如何在swift 3中使用相同的东西?

NotificationCenter.default.addObserver(self, selector: "handleInterruption", name: AVAudiosessionInterruptionNotification, object: nil)
Run Code Online (Sandbox Code Playgroud)

提前致谢!

pbo*_*dsk 5

看看这个很好的答案

正如它所说:

现在,所有系统通知类型都定义为Notification.Name上的静态常量; 即.UIApplicationDidFinishLaunching,.UITextFieldTextDidChange等

所以,在你的情况下,你可能正在寻找 Notification.Name.AVAudioSessionInterruption

我认为这应该对你有用:

NotificationCenter.default.addObserver(self, selector: #selector(handleInterruption), name: .AVAudioSessionInterruption, object: nil)
Run Code Online (Sandbox Code Playgroud)

希望有所帮助.