Reputation: 41
This is the code I had in swift 2.
How do I use the same thing in swift 3?
NotificationCenter.default.addObserver(self, selector: "handleInterruption", name: AVAudiosessionInterruptionNotification, object: nil)
Thanks in advance!
Upvotes: 4
Views: 1364
Reputation: 6876
Have a look at this fine answer
As it says:
All of the system notification types are now defined as static constants on Notification.Name; i.e. .UIApplicationDidFinishLaunching, .UITextFieldTextDidChange, etc.
So, in your case, you are probably looking for Notification.Name.AVAudioSessionInterruption
And I think this should work for you:
NotificationCenter.default.addObserver(self, selector: #selector(handleInterruption), name: .AVAudioSessionInterruption, object: nil)
Hope that helps.
Upvotes: 5