The iPhone SDK 3.0 introduced a GKPeerPickerControllerDelegate which can be found in the GameKit framework. That peek picker is great if you want to create a multiplayer game.
Game you said? So I will use the GameKit framework to establish a connection between my two (or more) players and I will use Cocos2D for my GUI…
The problem is, a Cocos2D view is not an UIView and our peer picker has been made to be running on top of an UIView. So we see the picker, we can cancel it, we can see the other devices in a nice (but not responding very well) tableView inside the picker BUT it’s not possible to choose one. In other words : the UITableView embeded in the picker is not working well because we added the picker in a Cocos2D view.
The first solution is to put a UIView (running the picker) on top of the Cocos2D view… I tested it and crap, it’s not working, the UITableView is still not responding.
My solution :
- dismiss the Cocos2D view - [[Director sharedDirector] end];
- add a UIView running the peer picker - [[[UIApplication sharedApplication] keyWindow] addSubview:[[[[ConnectionManagerViewController alloc] init] autorelease] view]];
- when you are ready to go back to a Cocos2D view, you have first to (re)attache the Director to the application’s window - [[Director sharedDirector] attachInWindow:[[UIApplication sharedApplication] keyWindow]];
- then you simply run your multiplayer scene - [[Director sharedDirector] runWithScene:[GameScene node]];
I will soon be writing more about the GameKit framework and Cocos2D with UIKit Views…

