Determine the best host for a multiplayer iOS game

I am using the following code to determine the best host to act as a server in a two-user iOS multiplayer game. The code is executed when all players are connected simultaneously on all devices.

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

      

The value is playerID

always null, which, according to the documentation, means that it cannot determine the best host. I am testing an app on an iPhone with iOS 6.1 along with the 6.1 simulator. The computer running the simulator and the iPhone are on the same wireless network. I tested calling the code above in a continuous manner at intervals on both devices and found out that if one of the devices goes offline, it detects the host.

Do I need two non-immune devices to test this? Or what else could be causing this?

+3


source to share


1 answer


For some reason it doesn't work with the simulator (or I couldn't get it to work).

I get a valid result most of the time using 2 devices. However, this is not always consistent, so you definitely need a backup option for host selection.

Besides



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

This is from the multiplayer tutorial - are you calling a method on both devices at the same time?

+1


source







All Articles