在应用程序中,正在调用invitationDidFail,有时它正确连接,但有时它不会...
否认连接的可能原因是什么?
// Display an alert sheet indicating a failure to connect to the peer.
- (void) invitationDidFail:(SessionManager *)session fromPeer:(NSString *)participantID
{
NSString *str;
if (alertView.visible) {
// Peer cancelled invitation before it could be accepted/rejected
// Close the invitation dialog before opening an error dialog
[alertView dismissWithClickedButtonIndex:0 animated:NO];
[alertView release];
str = [NSString stringWithFormat:@"%@ is busy.\nPlease again", participantID];
//[peerList removeAllObjects];
[self peerListDidChange:nil];
[self.tableData reloadData];
//[self TwoPlayer:self];
} else {
// Peer rejected invitation or exited app.
str = [NSString stringWithFormat:@"%@ is busy.\nPlease try again", participantID];
//[peerList removeAllObjects];
[self peerListDidChange:nil];
[self.tableData reloadData];
//[self TwoPlayer:self];
}
}
即使它不调用此方法,确定设备未与任何其他设备配对,那么有时它接受并调用didReceivedInvitation方法的原因是什么,或者有时它通过调用invitationDidFail来拒绝。< / p>
// Invitation dialog due to peer attempting to connect.
- (void) didReceiveInvitation:(SessionManager *)session fromPeer:(NSString *)participantID;
{
[alertView dismissWithClickedButtonIndex:1 animated:NO];
NSString *str = [NSString stringWithFormat:@"Incoming Invite from %@", participantID];
if (alertView.visible) {
[alertView dismissWithClickedButtonIndex:0 animated:NO];
[alertView release];
}
alertView = [[UIAlertView alloc]
initWithTitle:str
message:@"Do you wish to accept?"
delegate:self
cancelButtonTitle:@"Decline"
otherButtonTitles:nil];
[alertView addButtonWithTitle:@"Accept"];
[alertView show];
}
答案 0 :(得分:1)
当我最近使用连接编写应用程序时,我使用了GKSession。我花了几周的时间尝试用它调试连接问题,最后我放弃了并停止使用它。连接时GKSession似乎存在许多问题,特别是如果断开连接然后尝试在短时间内重新连接(短时间可能是1分钟或更长时间)。似乎连接没有正确删除,然后它没有正确地重新创建连接。
最后,我拿出了所有GKSession代码并改为使用它。做了一个享受 - 没有更多的连接问题。