ioscocoagame-centermultiplayer

Determine the best host in multiplayer game on iOS


I am using the following code to determine the best host to act as a server in a multiplayer iOS game with 2 users. The code is executed when all players has connected at the same time on all devices.

[myMatch chooseBestHostPlayerWithCompletionHandler: ^(NSString *playerID) {
    NSLog(@"The best host is: %@", playerID);
}];

The value of playerID is always null, which according to the documentation means that it couldn't determine the best host. I am testing the application on an iPhone with iOS 6.1 together with a simulator with version 6.1. The computer running the simulator and the iPhone are on the same wireless network. I've tested calling the code above in a continuous manner with an interval on both devices and found out that if one of the devices disconnect, it does determine a host.

Do I need two non-simulator devices to test this? Or what else could cause this?


Solution

  • For some reason it doesn't work with the simulator (or I haven't been able to make it work).

    I do get a valid result most of the time when using 2 devices. That said - it's not always consistent, so you definitely need a backup option for choosing the host.

    Also

    If you intend to search for the best server using this method, all devices in the match must be running on versions of Game Kit that support this method, and every device in the match must call this method at the same time.

    This is out of the Multiplayer guide - do you call the method on both devices at the same time?