GKSession正在搜索自己(相同的设备),为什么?即使在GKRocket的例子中,为什么会这样呢?
我怎么才能停止不进行自我连接呢?
发布于 2011-05-02 16:26:27
确保只有一个会话从设备打开。GKSession查找具有匹配id的会话...如果您使用相同的id从您的设备创建一个新会话,它将查找较旧的会话。
发布于 2012-02-15 07:22:18
你要做的就是使用:
session.available = NO;在正在搜索的设备上。只需在搜索结束时将其设置为YES即可。
如果会话是AppDelegate的一部分:
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication]delegate];发布于 2013-09-18 01:24:29
我在修改过的GKRocket版本中遇到了这个问题。当一个对等体断开连接时,应用程序返回到前面的屏幕,然后重新加载启动会话的视图。
您需要通过在应用程序中尽早实例化创建GKSession的类来修复此问题。用户在关闭应用程序之前,任何时候都不能再向后导航。然后,在整个导航堆栈中维护一个指向会话控制器类的指针,以便您可以调用对等列表等。
这些方法来自AppDelegate之后的第一个视图控制器
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
//We setup the GKSession at this stage so that we do not create duplicate sessions as
//the user navigates to and from the game lobby controller finding and managing peers
manager = [[SessionManager alloc] init];
manager.lobbyDelegate = nil; //There is no game lobby at this stage so we nil this.
[manager setupSession];
// call the session manager's setup method to create the session. It will start
//looking for peers right away, but we won't see that until we go to the game lobby
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
//Pass a pointer to the session manager along the line of segues
[[segue destinationViewController] setManager:self.manager];
}这段代码是从GKRocket修改而来的-请查看该教程,了解像setupSession这样的方法是做什么的。
https://stackoverflow.com/questions/5854364
复制相似问题