每次尝试时,什么GKSession都不会连接? [英] what GKSession doesn't connect on every attempt?

查看:86
本文介绍了每次尝试时,什么GKSession都不会连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在应用程序中,邀请DidFail被调用,有时它可以正确连接,但有时却不...

In application, invitationDidFail is being called, some time it connects properly, but sometime it doesn't...

拒绝连接的可能原因是什么?

what can be possible reasons of denying the connection?

// 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>

Even it doesn't call this method, It is sure that device is not paired to any other device, then what are reasons that sometime it do accept and call didReceivedInvitation method, or some time it does deny by calling invitationDidFail.

// 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];
}

推荐答案

当我最近使用连接编写应用程序时,我使用了GKSession.我花了数周的时间尝试调试它的连接问题,最后我放弃并停止使用它.连接时,GKSession似乎存在许多问题,尤其是当您断开连接然后尝试在很短的时间内重新连接(很短的时间可能是1分钟或更长时间)时.似乎连接没有正确断开,因此不能正确地重新建立连接.

When I was recently writing an application using connections, I used GKSession. I spent weeks trying to debug connection issues with it and in the end I gave up and stopped using it. There seems to be a number of issues with GKSession when connecting especially if you disconnect and then attempt to reconnect within a short time (a short time could be 1 minute or more). It seems that the connection doesn't properly get dropped and then it doesn't recreate the connection properly.

最后,我取出了所有的GKSession代码,并使用了它.工作了-没有更多的连接问题.

In the end I took out all the GKSession code and used this instead. Worked a treat - no more connection issues.

GCD异步套接字

这篇关于每次尝试时,什么GKSession都不会连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆