3

次のコードを使用して、2 人のユーザーがいるマルチプレイヤー iOS ゲームでサーバーとして機能する最適なホストを決定しています。コードは、すべてのプレイヤーがすべてのデバイスで同時に接続したときに実行されます。

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

の値playerIDは常に null です。これは、ドキュメントによると、最適なホストを決定できなかったことを意味します。iOS 6.1 を搭載した iPhone とバージョン 6.1 のシミュレーターでアプリケーションをテストしています。シミュレーターを実行しているコンピューターと iPhone は、同じワイヤレス ネットワーク上にあります。上記のコードを両方のデバイスで間隔を空けて連続的に呼び出すことをテストしたところ、デバイスの 1 つが切断された場合、ホストが特定されることがわかりました。

これをテストするには、シミュレーター以外のデバイスが 2 つ必要ですか? または、他に何がこれを引き起こす可能性がありますか?

4

1 に答える 1

1

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?

于 2013-03-20T16:23:58.713 に答える