【发布时间】:2012-02-21 08:04:17
【问题描述】:
为了读取对等点的新显示名称,我需要终止并更新 GKSession。将其设置为 nil 并重新启动它不起作用。在下面的代码中,for-loop 中显示可用对等点的 NSLog 未被调用(没有错误消息):
-(IBAction) btnRefresh:(id) sender {
self.currentSession = nil;
self.currentSession = [[GKSession alloc] initWithSessionID:@"anything" displayName:name sessionMode:GKSessionModePeer];
self.currentSession.delegate = self;
self.currentSession.available = YES;
self.currentSession.disconnectTimeout = 0;
[self.currentSession setDataReceiveHandler:self withContext:nil];
peerListAvailable = [[NSMutableArray alloc] initWithArray:[currentSession peersWithConnectionState:GKPeerStateAvailable]];
for (NSString *peer in peerListAvailable) {
NSLog(@"found available peer; checking name and ID... %@, %@",[currentSession displayNameForPeer:peer], peer);
}
将 currentSession 设置为 nil 并重新启动它有什么问题? 也许您知道另一种更新 GKSession 的方法? 提前非常感谢。
【问题讨论】: