首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >GKSession -杀死和更新会话

GKSession -杀死和更新会话
EN

Stack Overflow用户
提问于 2012-01-28 20:43:24
回答 1查看 1.2K关注 0票数 1

为了读取对等点的新显示名称,我需要杀死和更新GKSession。将其设置为零并重新启动它是行不通的。在下面的代码中,for-循环中显示可用对等点的NSLog不被调用(没有错误消息):

代码语言:javascript
复制
-(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设置为0并重新启动它有什么问题?也许你知道另一种更新GKSession的方法?提前谢谢。

EN

回答 1

Stack Overflow用户

发布于 2012-01-30 08:52:54

下面的方法说明了GKSession的设置和删除:

代码语言:javascript
复制
- (void)setupSession
{
    gkSession = [[GKSession alloc] initWithSessionID:nil displayName:nil sessionMode:GKSessionModePeer];
    gkSession.delegate = self;
    gkSession.disconnectTimeout = 5;
    gkSession.available = YES;
}

- (void)teardownSession
{
    gkSession.available = NO;
    [gkSession disconnectFromAllPeers];
}

如果您对深入研究感兴趣,请看一看GKSessionP2P,一个演示应用程序,它演示了GKSession的临时网络功能。该应用程序既在本地网络上做广告,又自动连接到可用的对等网络,从而建立了对等网络。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9048441

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档