我正在尝试使用自定义UI(没有GKMatchMakerViewController)实现实时多人游戏.我正在使用startBrowsingForNearbyPlayersWithReachableHandler:^(NSString*playerID,BOOL可达)来查找本地播放器,然后使用GKMatchmaker单例(我已经发起)启动匹配请求.
这是我遇到麻烦的地方.当我发送请求时,完成处理程序几乎立即触发,没有错误,并且它返回的匹配具有预期的玩家计数为零.同时,其他玩家肯定没有回应该请求
相关守则:
- (void) findMatch {
GKMatchRequest *request = [[GKMatchRequest alloc] init];
request.minPlayers = NUM_PLAYERS_PER_MATCH; //2
request.maxPlayers = NUM_PLAYERS_PER_MATCH; //2
if (nil != self.playersToInvite) {
// we always successfully get in this if-statement
request.playersToInvite = self.playersToInvite;
request.inviteeResponseHandler = ^(NSString *playerID, GKInviteeResponse response) {
[self.delegate updateUIForPlayer: playerID accepted: (response == GKInviteeResponseAccepted)];
};
}
request.inviteMessage = @"Let's Play!";
[self.matchmaker findMatchForRequest:request withCompletionHandler:^(GKMatch *match, NSError *error) {
if (error) {
// Print the error
NSLog(@"%@", error.localizedDescription);
} else
if (match != nil) { …Run Code Online (Sandbox Code Playgroud)