什么 GKSession 每次尝试都无法连接?

发布于 2024-11-17 17:30:20 字数 1852 浏览 2 评论 0原文

在应用程序中,正在调用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 拒绝的原因是什么。

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

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

公布 2024-11-24 17:30:20

当我最近编写使用连接的应用程序时,我使用了 GKSession。我花了几周的时间尝试调试它的连接问题,最后我放弃并停止使用它。连接时 GKSession 似乎存在许多问题,特别是如果您断开连接,然后尝试在短时间内重新连接(很短的时间可能是 1 分钟或更长时间)。看来连接没有正确删除,然后也没有正确重新创建连接。

最后我把GKSession的代码全部拿出来,用这个代替。工作顺利——不再有连接问题。

GCD 异步套接字

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.

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

GCD Async Socket

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文