Best way to detect a specific type of Event

the app I am working on uses external controllers … there are two distinct types (a gamepad, or the AppleTV Siri Remote)

When either establishes a connection, an event is fired (ConnectController), when either disconnects another event (DisconnectController) is fired.

Depending on which (or possibly BOTH) controllers are connected or disconnected an object is either instantiated, or set to nil (on disconnect)

There is one object class for each controller class. so at any moment, either one, or both, or neither can be nil

The app will use (and must have) a non-nil controller object. with the GamePad taking priority over the Siri Remote if possible

Detecting if/when a controller comes on line is not the issue. What I need to do it notifiy the user WHICH controller is currently to be used.

A scenario.

  1. the user starts the app
  2. the gamepad has NOT yet been paired
  3. the App detects and brings online the Siri Remote (almost alway available)
  4. the user then pairs the gamepad
  5. Notify the user that the gamepad has now taking over for Siri
  6. the gamepad times out
  7. Notifiy the user that the gamepad has gone off line, and Siri has taken control

Similar things need to happen if the Siri can’t be brought online either

in case anyone ever plays with Swift on AppleTV

import GameController
import Foundation
#if os(tvOS)
public var theGamePad      :  GCController?
public var theSiriRemote   :  GCController?
fileprivate var theControllerID :  Int = -1 // 0=gamePad 1=Siri -1=none


public func public_connectControllers() {
    var indexNumber = 0
    for controller in GCController.controllers() {
        if controller.extendedGamepad != nil && indexNumber==0 { // only support ONE controller for now
            theGamePad=controller
            controller.playerIndex = GCControllerPlayerIndex.init(rawValue: indexNumber)!
            indexNumber += 1
        }
        if controller.microGamepad != nil { theSiriRemote=controller }
    }
    checkForControllerChange()
}

public func public_disconnectControllers() {
    // which controllers remain? (if any)
    for controller in GCController.controllers() {
        if controller.extendedGamepad == nil { theGamePad    = nil }
        if controller.microGamepad    == nil { theSiriRemote = nil }
    }
    checkForControllerChange()
}

private func checkForControllerChange() {
    var newID : Int = -1
    if theSiriRemote != nil { newID=1 }
    if theGamePad    != nil { newID=0 }
    //
    if newID != theControllerID && newID>=0 { // controller type HAS changed
        print("Changed from \(theControllerID) to \(newID)")
    }
    if newID<0 {
        alert_NO_GAMEPAD()
    } else {
        theControllerID = newID
        theMsgBox.dismiss()
    }
}