0

I am working on a mobile app and I would like to know when a user closes the Airplay route selection window. In the documentation for the AVRoutePickerView, its delegate supposedly has a function, "routePickerViewDidEndPresentingRoutes" https://developer.apple.com/documentation/avkit/avroutepickerview

Here's my implementation. The Route selection detail opens and closes, but the delegate's function is not fired. Perhaps I don't understand Swift 5.2? How can I detect this change?

@available(iOS 11.0, *)
class RouteCheckDelegate: NSObject, AVRoutePickerViewDelegate  {
  func routePickerViewDidEndPresentingRoutes(_ routePickerView: AVRoutePickerView) {
    print("FINISHED PRESENTING ROUTES")
  }
}

@objc(RCTAirPlayButton)
@available(iOS 11.0, *)
class ShowAirplay: RCTViewManager {

  @objc
  override static func requiresMainQueueSetup() -> Bool {
    return true
  }

  override func view() -> AVRoutePickerView {
    let routerPickerView = AVRoutePickerView(frame: CGRect(x: 50, y: 50, width: 100, height: 100))
    let delegate = RouteCheckDelegate()
    routerPickerView.delegate = delegate
    return routerPickerView
  }
}```

jbodily
  • 3,613
  • 2
  • 20
  • 21
  • 1
    AVRoutePickerView `delegate` is _weak_. You are creating a RouteCheckDelegate object and then throwing it away. That is not how delegation works. Some _persistent object_ needs to adopt AVRoutePickerViewDelegate and function as delegate. – matt Apr 09 '20 at 20:06
  • I'll be darned if that wasn't it. – jbodily Apr 09 '20 at 20:15

0 Answers0