iOS Developer Library

Developer

GameController Framework Reference GCController Class Reference

Options
Deployment Target:

On This Page
Language:

GCController

A GCController object represents a connected physical game controller. Controllers can be connected directly to the device or through a wireless connection.

Inheritance


Conforms To


Import Statement


Swift

import GameController

Objective-C

@import GameController;

Availability


Available in iOS 7.0 and later.
  • Starts browsing for nearby controllers.

    Declaration

    Swift

    class func startWirelessControllerDiscoveryWithCompletionHandler(_ completionHandler: (() -> Void)!)

    Objective-C

    + (void)startWirelessControllerDiscoveryWithCompletionHandler:(void (^)(void))completionHandler

    Parameters

    completionHandler

    A block to be called when browsing ends.

    Discussion

    You should include a user interface in your game to allow the player to determine when controllers are discovered. When the user chooses to search for controllers, call this method. The device searches asynchronously for discoverable wireless controllers as well as controllers that are connected to iOS devices that have been placed in controller-forwarding mode. Whenever a new controller is connected, a GCControllerDidConnectNotification notification is posted. When no more devices can be found or the discovery process times out, the completion handler is called.

    If this method is called multiple times, only the block associated with the last invocation is called when discovery times out.

    Import Statement

    Objective-C

    @import GameController;

    Swift

    import GameController

    Availability

    Available in iOS 7.0 and later.

  • Stops browsing for nearby controllers.

    Declaration

    Swift

    class func stopWirelessControllerDiscovery()

    Objective-C

    + (void)stopWirelessControllerDiscovery

    Discussion

    This method may be called at any time. If a search for new wireless controllers in progress, that search ends and its completion handler is called.

    Import Statement

    Objective-C

    @import GameController;

    Swift

    import GameController

    Availability

    Available in iOS 7.0 and later.

  • The controllers connected to the device.

    Declaration

    Swift

    class func controllers() -> [AnyObject]!

    Objective-C

    + (NSArray *)controllers

    Return Value

    An array of GCController objects for all currently connected controllers.

    Discussion

    Whenever a controller is connected to or disconnected from the device, the array of controllers is updated and a notification is posted.

    Import Statement

    Objective-C

    @import GameController;

    Swift

    import GameController

    Availability

    Available in iOS 7.0 and later.

  • gamepad gamepad Property

    The gamepad profile. (read-only)

    Declaration

    Swift

    var gamepad: GCGamepad! { get }

    Objective-C

    @property(retain, readonly) GCGamepad *gamepad

    Discussion

    If the controller supports the gamepad profile, then this property holds a GCGamepad object. You use this object to access the input elements of the controller. If the controller does not support the gamepad profile, this property holds nil.

    Import Statement

    Objective-C

    @import GameController;

    Swift

    import GameController

    Availability

    Available in iOS 7.0 and later.

  • The extended gamepad profile. (read-only)

    Declaration

    Swift

    var extendedGamepad: GCExtendedGamepad! { get }

    Objective-C

    @property(retain, readonly) GCExtendedGamepad *extendedGamepad

    Discussion

    If the controller supports the extended gamepad profile, then this property holds a GCExtendedGamepad object. You use this object to access the input elements of the controller. If the controller does not support the extended gamepad profile, this property holds nil.

    Import Statement

    Objective-C

    @import GameController;

    Swift

    import GameController

    Availability

    Available in iOS 7.0 and later.

  • motion motion Property

    The motion input profile. (read-only)

    Declaration

    Swift

    var motion: GCMotion! { get }

    Objective-C

    @property(retain, readonly) GCMotion *motion

    Discussion

    If the controller supports the motion profile, then this property holds a GCMotion object. This profile is typically available when the controller is attached to a device that supports motion. You use this object to access the motion data of the controller. If the controller does not support the motion input profile, this property holds nil.

    Import Statement

    Objective-C

    @import GameController;

    Swift

    import GameController

    Availability

    Available in iOS 8.0 and later.

  • A block called when the controller’s pause button is pressed.

    Declaration

    Swift

    var controllerPausedHandler: ((GCController!) -> Void)!

    Objective-C

    @property(copy) void (^controllerPausedHandler)( GCController *controller)

    Discussion

    All controllers have a button that allows the player to suspend the current gameplay. When pressed, the block associated with this property is called. Your game should toggle between pausing and resuming gameplay. When paused, your game must display a user interface that indicates that the game is paused. This interface should tell the player how to resume the game. The exact design of this user interface is up to you; typically it should match the style of the rest of your game.

    If your game is paused for other reasons defined by your game, and is in a state where it can be resumed, pressing the pause button should resume gameplay. Which is to say that the pause button on the controller as well as other things that pause gameplay should all present a seamless interface to the player.

    Import Statement

    Objective-C

    @import GameController;

    Swift

    import GameController

    Availability

    Available in iOS 7.0 and later.

  • A Boolean property that indicates whether the controller is closely integrated with the device. (read-only)

    Declaration

    Swift

    var attachedToDevice: Bool { get }

    Objective-C

    @property(readonly, getter=isAttachedToDevice) BOOL attachedToDevice

    Discussion

    If YEStrue, then the controller is attached to the device or is quite close to it. If NOfalse, then the controller is not guaranteed to be near the device. This property is provided to allow you to make informed decisions about what other user interface interactions with the device will make sense.

    Import Statement

    Objective-C

    @import GameController;

    Swift

    import GameController

    Availability

    Available in iOS 7.0 and later.

  • The name of the vendor that manufactured the controller. (read-only)

    Declaration

    Swift

    var vendorName: String! { get }

    Objective-C

    @property(readonly, copy) NSString *vendorName

    Discussion

    The value of this property may be nil and is not guaranteed to be unique.

    Import Statement

    Objective-C

    @import GameController;

    Swift

    import GameController

    Availability

    Available in iOS 7.0 and later.

  • The player index assigned to the controller.

    Declaration

    Swift

    var playerIndex: Int

    Objective-C

    @property(nonatomic) NSInteger playerIndex

    Discussion

    The player index is a value that is persistently stored on the device for a particular controller. Once assigned, the device uses the same index for that controller whenever it is discovered. Your app can use this index to identify a particular controller in the future. The default value is GCControllerPlayerIndexUnset. An index value can be 0 or any positive integer value, but you should almost always use numbers between 0 and 3. When you choose a number in this range, a matching LED on the controller lights up.

    Import Statement

    Objective-C

    @import GameController;

    Swift

    import GameController

    Availability

    Available in iOS 7.0 and later.

  • Predefined values for controller indices.

    Declaration

    Swift

    var GCControllerPlayerIndexUnset: Int { get }

    Objective-C

    enum { GCControllerPlayerIndexUnset = -1, };

    Constants

    • GCControllerPlayerIndexUnset

      GCControllerPlayerIndexUnset

      The default index for a player on a controller. No lights are lit on the controller.

      Available in iOS 7.0 and later.

  • Posted immediately after a new controller is connected to the device.

    The notification object is the GCController object that represents the connected device.

    Import Statement

    Objective-C

    @import GameController;

    Swift

    import GameController

    Availability

    Available in iOS 7.0 and later.

  • Posted immediately after a controller is disconnected from the device.

    The notification object is the GCController object that represented the disconnected device.

    Import Statement

    Objective-C

    @import GameController;

    Swift

    import GameController

    Availability

    Available in iOS 7.0 and later.