Thanks for the links. They were helpful, but not complete.
I've got an AVRoutePickerView on my screen, and I added an observer to the NotificationCenter (as directed in the documentation). However, when I choose the AppleTV from the view picker, I get the following error message:
MPMediaControlsRemoteViewController Dismissing because view service terminated
I was unable to find anything in a Google search regarding a cause/solution for that message.
However, if I first mirror my iPhone to the AppleTV before launching my app, the observer method does get fired, and I can see the 2nd screen. That's definitely further than I had gotten before, but I'd like to know how to get the AVRoutePickerView observer to work properly. Here are the pertinent parts of my code (a SpriteKit game), in case it is needed for reference:
GameViewController:
override func viewDidLoad() {
super.viewDidLoad()
let notifier = NotificationCenter.default
notifier.addObserver(self, selector: #selector(GameViewController.screenDidConnect), name: NSNotification.Name.UIScreenDidConnect, object: nil)
notifier.addObserver(self, selector: #selector(GameViewController.screenDidDisconnect), name: NSNotification.Name.UIScreenDidDisconnect, object: nil)
let skView = self.view as! SKView
let scene = TitleScene(size: (skView.bounds.size)!)
scene.backgroundColor = SKColor.black
skView.presentScene(scene)
}
@objc fileprivate func screenDidConnect(notification: NSNotification) {
print("GameViewController: Screen was connected: \n\(notification)")
print("# of Screens: \(UIScreen.screens.count)")
}
@objc fileprivate func screenDidDisconnect(notification: NSNotification) {
print("GameViewController: Screen was disconnected: \n\(notification)")
print("# of Screens: \(UIScreen.screens.count)")
}
Any ideas as to what I'm missing?