AVAudio session interruption
Asked Answered
F

1

5

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.

Frown answered 3/10, 2018 at 16:59 Comment(0)
F
8

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

NotificationCenter.default.addObserver(self, selector: #selector(handleInterruption(_:)), name: AVAudioSession.interruptionNotification, object: nil)
Frown answered 4/10, 2018 at 15:36 Comment(1)
Do we need to remove the observer for this?Bats

© 2022 - 2024 — McMap. All rights reserved.