iOS Developer Library

Developer

GameKit Framework Reference GKPeerPickerControllerDelegate Protocol Reference

Options
Deployment Target:

On This Page
Language:

GKPeerPickerControllerDelegate

The GKPeerPickerControllerDelegate protocol is implemented on an object to customize the behavior of a GKPeerPickerController object. The delegate is called by the peer picker to create a session object and to respond as the session is configured by the controller.

Inheritance


Not Applicable

Import Statement


Swift

import GameKit

Objective-C

@import GameKit;

Availability


Available in iOS 3.0 and later.
  • Tells the delegate that the user selected a connection type.

    Declaration

    Swift

    optional func peerPickerController(_ picker: GKPeerPickerController!, didSelectConnectionType type: GKPeerPickerConnectionType)

    Objective-C

    - (void)peerPickerController:(GKPeerPickerController *)picker didSelectConnectionType:(GKPeerPickerConnectionType)type

    Parameters

    picker

    The controller for the peer picker dialog.

    type

    The type of network connection chosen by the user.

    Discussion

    If the peer picker is configured to allow users to choose between multiple connection types, this method is called when users select the connection type they want to use. Your delegate implements this method if you want to override the behavior for a particular connection type.

    • - (void)peerPickerController:(GKPeerPickerController *)picker didSelectConnectionType:(GKPeerPickerConnectionType)type {
    • if(type == GKPeerPickerConnectionTypeOnline) {
    • [picker dismiss];
    • [picker autorelease];
    • // Display your own user interface here.
    • }

    Import Statement

    Objective-C

    @import GameKit;

    Swift

    import GameKit

    Availability

    Available in iOS 3.0 and later.

  • Asks the delegate to return a session for the specified connection type.

    Declaration

    Swift

    optional func peerPickerController(_ picker: GKPeerPickerController!, sessionForConnectionType type: GKPeerPickerConnectionType) -> GKSession!

    Objective-C

    - (GKSession *)peerPickerController:(GKPeerPickerController *)picker sessionForConnectionType:(GKPeerPickerConnectionType)type

    Parameters

    picker

    The controller requesting the session.

    type

    The type of connection the controller wants to configure.

    Discussion

    Your delegate is responsible for providing a GKSession to use to find and connect to other devices. When the peer picker needs a session, it calls this method. Your application can either create a new session or return a previously created session to the peer picker. The session that your application returns to the peer picker must advertise itself as a peer (GKSessionModePeer).

    If your delegate does not implement this method and the user selected a network of type GKPeerPickerConnectionTypeNearby, the peer controller allocates a new session that advertises itself as a peer (GKSessionModePeer) with the default sessionID and displayName parameters.

    Special Considerations

    In iOS 3.0, your delegate receives requests only for networks of type GKPeerPickerConnectionTypeNearby.

    Import Statement

    Objective-C

    @import GameKit;

    Swift

    import GameKit

    Availability

    Available in iOS 3.0 and later.

  • Tells the delegate that the controller connected a peer to the session.

    Declaration

    Swift

    optional func peerPickerController(_ picker: GKPeerPickerController!, didConnectPeer peerID: String!, toSession session: GKSession!)

    Objective-C

    - (void)peerPickerController:(GKPeerPickerController *)picker didConnectPeer:(NSString *)peerID toSession:(GKSession *)session

    Parameters

    picker

    The controller that connected the peer.

    peerID

    The identification string for the peer that connected to the session.

    session

    The session that the peer is connected to.

    Discussion

    Once a peer is connected to the session, your application should take ownership of the session, dismiss the peer picker, and then use the session to communicate with the other peer.

    Import Statement

    Objective-C

    @import GameKit;

    Swift

    import GameKit

    Availability

    Available in iOS 3.0 and later.

  • Tells the delegate that the user canceled the connection attempt.

    Declaration

    Swift

    optional func peerPickerControllerDidCancel(_ picker: GKPeerPickerController!)

    Objective-C

    - (void)peerPickerControllerDidCancel:(GKPeerPickerController *)picker

    Parameters

    picker

    The controller for the peer picker dialog.

    Discussion

    After this method returns, the controller dismisses the picker interface.

    Import Statement

    Objective-C

    @import GameKit;

    Swift

    import GameKit

    Availability

    Available in iOS 3.0 and later.