Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

chooseBestHostPlayerWithCompletionHandler returns null

The following code returns best host as null. How can I get it to work?

[gameKitHelper.match chooseBestHostPlayerWithCompletionHandler: ^(NSString *playerID) {
    gameKitHelper.hostingPlayer = [playerID retain];
    NSLog(@"Best host = %@",gameKitHelper.hostingPlayer);
}];
like image 802
jyek Avatar asked Jan 30 '26 19:01

jyek


1 Answers

I found a simple solution (instead of generating a random number which requires additional negotiation and data transfer) is to simply compare [[GKLocalPlayer localPlayer] playerID] with the playerIDs in the match and choose the first one ordered ascending. This can be done on all the devices, guarantees a unique playerID as host and guarantees the same unique playerID is chosen on all devices.

like image 176
Gujamin Avatar answered Feb 01 '26 21:02

Gujamin