What's New / Connectivity & Hardware

What's new in GameController

+12 New~1 DeprecatediOS · macOS · tvOS · visionOS

GameController is Apple's API for discovering game controllers and reading their input, along with related hardware such as keyboards, mice, and spatial accessories. It reports connection events, button and axis state, and device configuration.

12 new APIs, 1 deprecation, no removals. New additions include the Action and Activity enums, the DidConnectMessage and DidDisconnectMessage structs, GCControllerHomeButtonSettingsManager (with Action.disabled), GCDevicePhysicalInput.inputState, the GCDeviceType.spatialAccessory case, and the GCSpatialAccessoryDidConnect and GCSpatialAccessoryDidDisconnect notification names. GCControllerElement.SystemGestureState.alwaysReceive is deprecated.

New

12
extension

GCControllerHomeButtonSettingsManager

NewiOSmacOS
extension GCControllerHomeButtonSettingsManager
Declaration
extension GCControllerHomeButtonSettingsManager {

    /// Get the current controller Home button action.
    ///
    public func readControllerHomeButtonAction() throws -> GCControllerHomeButtonSettingsManager.Action
}
extension

NotificationCenter.MessageIdentifier

NewvisionOS
extension NotificationCenter.MessageIdentifier where Self == NotificationCenter.BaseMessageIdentifier<GCSpatialAccessory.DidConnectMessage>
Declaration
extension NotificationCenter.MessageIdentifier where Self == NotificationCenter.BaseMessageIdentifier<GCSpatialAccessory.DidConnectMessage> {

    /// The identifier of the message that posts after a spatial accessory
    /// connects to the device.
    public static var didConnect: NotificationCenter.BaseMessageIdentifier<GCSpatialAccessory.DidConnectMessage> { get }
}
extension

NotificationCenter.MessageIdentifier

NewvisionOS
extension NotificationCenter.MessageIdentifier where Self == NotificationCenter.BaseMessageIdentifier<GCSpatialAccessory.DidDisconnectMessage>
Declaration
extension NotificationCenter.MessageIdentifier where Self == NotificationCenter.BaseMessageIdentifier<GCSpatialAccessory.DidDisconnectMessage> {

    /// The identifier of the message that posts after a spatial accessory
    /// disconnects from the device.
    public static var didDisconnect: NotificationCenter.BaseMessageIdentifier<GCSpatialAccessory.DidDisconnectMessage> { get }
}
enum

GCControllerHomeButtonSettingsManager.Action

NewiOSmacOS
public enum Action : Int, @unchecked Sendable
Declaration
public enum Action : Int, @unchecked Sendable {

    /** The controller home button action could not be accessed. */
    case unavailable = 0

    /** The controller home button action opens the current application. */
    case openCurrentApplication = 1

    /** The controller home button action performs some other action. */
    case other = 9223372036854775807
}
enum

GCControllerHomeButtonSettingsManager.Activity

NewiOSmacOS
public enum Activity : Int, @unchecked Sendable
Declaration
public enum Activity : Int, @unchecked Sendable {

    /** Customize the action that occurs in response to long press of the
     *  Home button. */
    case customizeAction = 1

    /** Disable the system Home button actions while this app has focus. */
    case customizeOverrides = 2
}
case

GCControllerHomeButtonSettingsManager.Action.disabled

NewmacOS
case disabled = -1
func

GCDevicePhysicalInput.inputState

NewvisionOS
func inputState(forSpatialAccessoryAnchorTimestamp timestamp: TimeInterval) -> (any GCDevicePhysicalInputState)?
var

GCDeviceType.spatialAccessory

NewvisionOS
open class var spatialAccessory: GCDeviceType { get }
struct

GCSpatialAccessory.DidConnectMessage

NewvisionOS
public struct DidConnectMessage : NotificationCenter.MainActorMessage

A message that posts after a spatial accessory connects to the device.

Use the .didConnect identifier with NotificationCenter to listen for this message.

let observation = NotificationCenter.default.addObserver(of: GCSpatialAccessory.self, for: .didConnect) { message in
   let accessory = message.spatialAccessory
}

Connections of spatial accessories will be reflected in the spatialAccessories array of the GCSpatialAccessory class when the message posts.

Declaration
public struct DidConnectMessage : NotificationCenter.MainActorMessage {

    /// A type which you can optionally post and observe along with this `MainActorMessage`.
    public typealias Subject = GCSpatialAccessory

    /// A optional name corresponding to this type, used to interoperate with notification posters and observers.
    public static var name: Notification.Name { get }

    /// The spatial accessory object that connected to the device.
    public var spatialAccessory: GCSpatialAccessory

    public init(spatialAccessory: GCSpatialAccessory)

    /// Converts a posted notification into this main actor message type for any observers.
    ///
    /// To implement this method in your own `MainActorMessage` conformance, retrieve values from the ``Notification``'s ``Notification/userInfo`` and set them as properties on the message.
    /// - Parameter notification: The posted ``Notification``.
    /// - Returns: The converted `MainActorMessage` or `nil` if conversion is not possible.
    @MainActor public static func makeMessage(_ notification: Notification) -> GCSpatialAccessory.DidConnectMessage?
}
struct

GCSpatialAccessory.DidDisconnectMessage

NewvisionOS
public struct DidDisconnectMessage : NotificationCenter.MainActorMessage

A message that posts after a spatial accessory disconnects from the device.

Use the .didDisconnect identifier with NotificationCenter to listen for this message.

let observation = NotificationCenter.default.addObserver(of: GCSpatialAccessory.self, for: .didDisconnect) { message in
   let spatialAccessory = message.spatialAccessory
}
Declaration
public struct DidDisconnectMessage : NotificationCenter.MainActorMessage {

    /// A type which you can optionally post and observe along with this `MainActorMessage`.
    public typealias Subject = GCSpatialAccessory

    /// A optional name corresponding to this type, used to interoperate with notification posters and observers.
    public static var name: Notification.Name { get }

    /// The spatial object that disconnected from the device.
    public var spatialAccessory: GCSpatialAccessory

    public init(spatialAccessory: GCSpatialAccessory)

    /// Converts a posted notification into this main actor message type for any observers.
    ///
    /// To implement this method in your own `MainActorMessage` conformance, retrieve values from the ``Notification``'s ``Notification/userInfo`` and set them as properties on the message.
    /// - Parameter notification: The posted ``Notification``.
    /// - Returns: The converted `MainActorMessage` or `nil` if conversion is not possible.
    @MainActor public static func makeMessage(_ notification: Notification) -> GCSpatialAccessory.DidDisconnectMessage?
}
let

NSNotification.Name.GCSpatialAccessoryDidConnect

NewvisionOS
public static let GCSpatialAccessoryDidConnect: NSNotification.Name
let

NSNotification.Name.GCSpatialAccessoryDidDisconnect

NewvisionOS
public static let GCSpatialAccessoryDidDisconnect: NSNotification.Name

Deprecated

1
case

GCControllerElement.SystemGestureState.alwaysReceive

DeprecatediOSmacOStvOSvisionOS
case alwaysReceive = 1
DeprecatedGCControllerElement.SystemGestureState.disabled

No APIs match your filter.

← More in Connectivity & Hardware