Protocol: GKSessionDelegate
Overview
An object implements the GKSessionDelegate protocol to control the behavior of a GKSession object. The delegate is called when other visible peers change their state relative to the session. It is also called to determine whether another peer is allowed to connect to the session.Received by the delegate when an attempt to connect to another peer failed. (required)Sent to the delegate when a serious error has occurred in the session. (required)Received by the delegate when a remote peer wants to create a connection to the session. (required)Received by the delegate when a peer changes state. (required)
Instance Method Summary (collapse)
-
- session:connectionWithPeerFailed:withError:
Received by the delegate when an attempt to connect to another peer failed.
-
- session:didFailWithError:
Sent to the delegate when a serious error has occurred in the session.
-
- session:didReceiveConnectionRequestFromPeer:
Received by the delegate when a remote peer wants to create a connection to the session.
-
- session:peer:didChangeState:
Received by the delegate when a peer changes state.
Instance Method Details
- (Object) session(session, connectionWithPeerFailed:peerID, withError:error)
Received by the delegate when an attempt to connect to another peer failed. (required) The error parameter can be used to inform the user of why the connection failed. Important: If a GKPeerPickerController object is being used to configure the session, the controller handles this message automatically. Your delegate can ignore it if the peer picker dialog is in use.
- (Object) session(session, didFailWithError:error)
Sent to the delegate when a serious error has occurred in the session. (required) This method is called when a serious internal error occurred in the session. Your application should disconnect the session from other peers and release the session.
- (Object) session(session, didReceiveConnectionRequestFromPeer:peerID)
Received by the delegate when a remote peer wants to create a connection to the session. (required) The delegate should call the session’s acceptConnectionFromPeer:error: method if it wants to accept the connection or the denyConnectionFromPeer: method if it wants to refuse the connection.Important: If a GKPeerPickerController object is being used to configure the session, the controller handles this message automatically. Your delegate can ignore it if the peer picker dialog is in use. If your application is not using a GKPeerPickerController object to configure the session, your delegate must implement this method as described above.
- (Object) session(session, peer:peerID, didChangeState:state)
Received by the delegate when a peer changes state. (required) A session calls this method whenever a visible peer changes it state relative to itself. The action your delegate should take depends on what state the peer moved to.When a peer first becomes visible to the session, it appears with a state of GKPeerStateAvailable. Your application should show this peer in its user interface. If the peer changes its state to GKPeerStateUnavailable, it no longer accepts connection requests and your application should remove it from the user interface.The delegate should ignore GKPeerStateConnecting changes and implement the session:didReceiveConnectionRequestFromPeer: method instead.When a peer is connected (GKPeerStateConnected), your application may send data to the peer and receive data from the peer. If a connection to a peer is lost or if the peer deliberately disconnects (GKPeerStateDisconnected), your application should stop sending messages to this peer.Important: If a GKPeerPickerController object is being used to configure the session, the controller handles updates for the GKPeerStateAvailable, GKPeerStateUnavailable, and GKPeerStateConnected states. Your delegate can ignore state changes if the peer picker dialog is in use.