gpt4 book ai didi

iphone - 接受传入请求时 Gamekit API 错误

转载 作者:行者123 更新时间:2023-12-03 19:55:09 26 4
gpt4 key购买 nike

我做了一个带蓝牙模式的iPhone游戏,可以通过蓝牙进行1对1的游戏。我的选择器实现如下:

picker = [[GKPeerPickerController alloc] init];
picker.delegate = self;
picker.connectionTypesMask = GKPeerPickerConnectionTypeNearby;
[picker show];

我不知道哪个代码给出了错误,所以我还将粘贴与选择器有关的所有其他方法的代码:

- (void) receiveData:(NSData *)data fromPeer:(NSString *)peer inSession: (GKSession *)session context:(void *)context {
NSString *dataString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSDictionary *dataDictionary = [NSDictionary dictionaryWithObjects: [NSArray arrayWithObjects:dataString, peer, session, nil] forKeys:[NSArray arrayWithObjects:@"data", @"peer", @"session", nil]];
[dataString release];
[self performSelectorOnMainThread:@selector(receivedData:) withObject:dataDictionary waitUntilDone:YES];
}
- (GKSession *)peerPickerController:(GKPeerPickerController *)picker
sessionForConnectionType:(GKPeerPickerConnectionType)type {
// Create a new session if one does not already exist
if (!self.currentSession) {
self.currentSession = [[[GKSession alloc] initWithSessionID:@"Session" displayName:nil sessionMode:GKSessionModePeer] autorelease];
self.currentSession.delegate = self;
}
return self.currentSession;
}
-(void)peerPickerController:(GKPeerPickerController *)pk didConnectPeer:(NSString *)peerID toSession:(GKSession *)session {
self.currentSession = session;
session.delegate = self;
[session setDataReceiveHandler:self withContext:nil];
picker.delegate = nil;
[picker dismiss];
[picker autorelease];
}
-(void)peerPickerControllerDidCancel:(GKPeerPickerController *)pk {
picker.delegate = nil;
[picker autorelease];
[self.navigationController popViewControllerAnimated:YES];
}
// FAIL
- (void)session:(GKSession *)session didFailWithError:(NSError *)error {
NSLog(@"error : %@", [error description]);
}
// SESSION VIND ANDERE SESSION -> CONNECT
-(void)session:(GKSession *)session peer:(NSString *)peerID didChangeState:(GKPeerConnectionState)state {
switch (state) {
case GKPeerStateConnected:
NSLog(@"connect met peer %@", [currentSession displayNameForPeer:peerID]);
[self generateRandomNumberAndSendIt];
break;
case GKPeerStateDisconnected:
NSLog(@"disconnected");
[self.currentSession disconnectFromAllPeers];
currentSession = nil;
[self.navigationController popViewControllerAnimated:YES];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Whoopsie" message:@"The connection failed" delegate:nil cancelButtonTitle:@"Okido" otherButtonTitles:nil];
[alert show];
[alert release];
[super viewDidDisappear:YES];
break;
}
}

有时,当我接受传入请求时,选择器会在一台设备上删除自身,而在另一台设备上我会收到错误:wait_fences:无法接收回复:10004003。我认为这与alertview本身有关。我在此 View 中设置了其他警报 View 。

希望大家能够帮助我。

提前致谢。

最佳答案

你需要设置一些断点并调试代码崩溃的地方,任何人都不可能确定你的代码在哪里崩溃,我们能做的最好的就是通过指出代码中的奇怪之处来猜测。该错误甚至可能不在您提供的代码中。

正如其他人提到的,您绝对不应该在非 viewDidAppear: 方法中使用语句 [super viewDidDisappear:YES];

我还猜测,如果您正在调试,那么控制台中会出现比 wait_fences: failed to receive reply: 10004003 更有用的错误消息。确保您已对所有异常启用断点。如果您不知道该怎么做,here are some instructions 。单步调试异常,找出它在哪一行,并找出抛出的错误。

你的[picker autorelease];调用也有点奇怪。如果您想自动释放选择器,只需执行 picker = [[[GKPeerPickerController alloc] init] autorelease]; 即可。将 autorelease 语句放在 GameKit 委托(delegate)方法中很奇怪。

关于iphone - 接受传入请求时 Gamekit API 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11417121/

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