Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AVAudio session interruption

Trying to handle audio interruption in my project.

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.

The Documents used:

func setupNotifications() {
let notificationCenter = NotificationCenter.default
notificationCenter.addObserver(self, selector: #selector(handleInterruption), name: .AVAudioSessionInterruption, object: nil)

}

But the document isn't updated for swift 4.2.

like image 512
Iam Wayne Avatar asked Oct 03 '18 16:10

Iam Wayne


1 Answers

There are bugs in Xcode migrator tool. The correct fix is,

NotificationCenter.default.addObserver(self, selector: #selector(handleInterruption(_:)), name: AVAudioSession.interruptionNotification, object: nil)
like image 190
Iam Wayne Avatar answered Sep 28 '22 12:09

Iam Wayne