表达式类型不明确,没有更多上下文 AVAudioSession
Type of expression is ambiguous without more context AVAudioSession
我正在尝试添加通知观察器以检测耳机何时被取下以及音乐何时停止播放。我关注了Audio Session。我正在尝试搜索 Swift 4.2 语法,从 Apple 的原始代码中更改了一些内容,但我仍然收到此错误:
Type of expression is ambiguous without more context
我做错了什么?让我知道是否需要添加更多代码
override func awakeFromNib() {
super.awakeFromNib()
NotificationCenter.default.addObserver(self, selector: #selector(audioRouteChanged), name: .AVAudioSession.routeChangeNotification, object: nil)
//Error this line: Type of expression is ambiguous without more context
}
@objc func audioRouteChanged(notification: Notification) {
guard let userInfo = notification.userInfo else { return }
guard let reason = userInfo[AVAudioSessionRouteChangeReasonKey] as? Int else { return }
if reason == AVAudioSession.RouteChangeReason.oldDeviceUnavailable.hashValue {
// headphones plugged out
// continue playback or change the play/pause icon
playPauseButton.setImage(#imageLiteral(resourceName: "play"), for: .normal)
miniPlayPauseButton.setImage(#imageLiteral(resourceName: "play"), for: .normal)
}
}
去掉AVAudioSession前面的点name: .AVAudioSession.routeChangeNotification
我正在尝试添加通知观察器以检测耳机何时被取下以及音乐何时停止播放。我关注了Audio Session。我正在尝试搜索 Swift 4.2 语法,从 Apple 的原始代码中更改了一些内容,但我仍然收到此错误:
Type of expression is ambiguous without more context
我做错了什么?让我知道是否需要添加更多代码
override func awakeFromNib() {
super.awakeFromNib()
NotificationCenter.default.addObserver(self, selector: #selector(audioRouteChanged), name: .AVAudioSession.routeChangeNotification, object: nil)
//Error this line: Type of expression is ambiguous without more context
}
@objc func audioRouteChanged(notification: Notification) {
guard let userInfo = notification.userInfo else { return }
guard let reason = userInfo[AVAudioSessionRouteChangeReasonKey] as? Int else { return }
if reason == AVAudioSession.RouteChangeReason.oldDeviceUnavailable.hashValue {
// headphones plugged out
// continue playback or change the play/pause icon
playPauseButton.setImage(#imageLiteral(resourceName: "play"), for: .normal)
miniPlayPauseButton.setImage(#imageLiteral(resourceName: "play"), for: .normal)
}
}
去掉AVAudioSession前面的点name: .AVAudioSession.routeChangeNotification