从选择器参数中的NotificationCenter.default.addObserver调用函数

时间:2018-09-15 22:59:32

标签: selector add notificationcenter

我对Swift和Objective C完全陌生。在这里,我试图从以下语句调用函数。但是,Xcode将其显示为无效语法。您能帮忙指出此语法有什么问题吗?

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

func handleInterruption(notification: NSNotification) {
    player.pauseAudio()

    let interruptionTypeAsObject = notification.userInfo![AVAudioSessionInterruptionTypeKey] as! NSNumber
    let interruptionType = AVAudioSessionInterruptionType(rawValue: interruptionTypeAsObject.uintValue)
    if let type = interruptionType {
        if type == .ended {
            player.playAudio()
        }
    }
}

0 个答案:

没有答案