AVAudioSession interruption notification


(IamWayne) #1

This code used to work in swift 4.

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

Since updating to Swift 4.2 it gave me suggestion to change to

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

After changing to the suggested fix, I am getting Error: Type 'Notification.Name' (aka 'NSNotification.Name') has no member 'AVAudioSession'

Any help would be appreciated.


(Zach Wolfe) #2

Seems like a bug in the migrator tool. In any case, AVAudioSession.interruptionNotification is what you want (without the Notification.Name prefix).


(IamWayne) #3

@zachrwolfe, Thank you. This solved my issues.