如何检测在 SwiftUI 中的 UIViewRepresentable AVRoutePickerView 上选择了哪个选项?

问题描述 投票:0回答:0

我在 SwiftUI 中使用

AVRoutePickerView
如下所示:

import SwiftUI

struct AirPlayView: UIViewRepresentable {
    
    private let routePickerView = AVRoutePickerView()

    func makeUIView(context: UIViewRepresentableContext<AirPlayView>) -> UIView {
        UIView()
    }

    func updateUIView(_ uiView: UIView, context: UIViewRepresentableContext<AirPlayView>) {
        uiView.addSubview(routePickerView)
    }
    
    func showAirPlayMenu() {
        for view: UIView in routePickerView.subviews {
            if let button = view as? UIButton {
                button.sendActions(for: .touchUpInside)
                break
            }
        }
    }
}

当一个选项被点击时(比如扬声器),一个

AVAudioSession.routeChangeNotification
被发送,我正在听。但是,我遇到了第三方 API 的问题,该 API 也发送了不需要的
AVAudioSession.routeChangeNotification
。我想忽略此通知,但我无法更改此 API 的实现方式。我怎样才能忽略不需要的通知,但仍然收听从
AVRoutePickerView
发送的通知?有什么方法可以让我知道用户已经从 SwiftUI 中的
AVRoutePickerView
中选择了选项?

swift swiftui avaudiosession
© www.soinside.com 2019 - 2024. All rights reserved.