gpt4 book ai didi

iphone - GKSession 问题 - Objective-C GameKit

转载 作者:太空狗 更新时间:2023-10-30 03:51:04 26 4
gpt4 key购买 nike

好的,我一直在尝试创建我自己的 GKSession 对象,但委托(delegate)方法在控制台中给我一个错误,我还没有弄清楚如何修复。我想知道是否有人有任何建议或遇到过这个问题? *请注意 - 变量 peerStatus 在我的代码的其他地方定义。对等点可以被赋予“kServer”或“kClient”状态。我宁愿将每个定义在 GKSessionModeServer 或 GKSessionModeClient 中,因为我读过如果对等点在 GKSessionModePeer 中,性能时间实际上会变慢,因为它必须完成客户端和服务器的工作。

- (GKSession *)peerPickerController:(GKPeerPickerController *)picker sessionForConnectionType:(GKPeerPickerConnectionType)type {
if (peerStatus == kServer) {
GKSession *session = [[GKSession alloc] initWithSessionID:@"Josh_Land" displayName:nil sessionMode:GKSessionModeServer];
return [session autorelease];
}
else {
GKSession *session = [[GKSession alloc] initWithSessionID:@"Josh_Land" displayName:nil sessionMode:GKSessionModeClient];
return [session autorelease];
}
}

整个错误代码是:

监听端口 563862009-06-30 10:31:41.892 GKTank[17756:20b] *** 由于未捕获的异常“GKInvalidArgumentException”而终止应用程序,原因:“必须提供具有 GKSessionModePeer 模式的有效 GKSession 对象,或创建默认 GKSession对象在 -peerPickerController:sessionForConnectionType: 的实现中返回 'nil'。提供的对象是:发送 0 个数据包:rush(0 个数据包 0 字节):rely(0 个数据包 0 个字节):rtry(0 个数据包 0 个字节):sack(0 个数据包 0 个字节):当前加权平均 rtt(0 毫秒)与 session 模式:0'2009-06-30 10:31:41.893 GKTank[17756:20b] 堆栈:( 807902715, 2452446779, 807986683, 807986522, 927035842, 927037074, 927038407, 815223834, 927038949, 9245, 8562, 814709201, 815110321, 815119058, 815114270, 814813151, 814722763, 814748641, 839148405, 807687520, 807683624, 839142449, 839142646, 814752238)

最佳答案

我实际上还没有使用 GameKit 实现任何东西,但只是查看文档,看起来只有在使用 GKSessionModePeer 时才能使用 GKPeerPickerController。如果您想使用 GKSessionModeServer/Client,您需要直接使用 session 及其委托(delegate)。请参阅 Game Kit 编程指南中关于 Implementing a Server 的部分和 Connecting to a Service .

您的主要功能将围绕 GKSessionDelegate 方法
-session:peer:didChangeState: 在客户端和服务器模式下,
-acceptConnectionFromPeer:error:-denyConnectionFromPeer: 在服务器模式下。

关于iphone - GKSession 问题 - Objective-C GameKit,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1064008/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com