[英]iOS Gamecenter Programmatic Matchmaking
我正在嘗試通過自定義UI(無GKMatchMakerViewController
)實現實時多人游戲。 我正在使用startBrowsingForNearbyPlayersWithReachableHandler: ^(NSString *playerID, BOOL reachable)
查找本地玩家,然后使用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)
{
self.currentMatch = match;
self.currentMatch.delegate = self;
// All players are connected
if (match.expectedPlayerCount == 0)
{
// start match
[self startMatch];
}
[self stopLookingForPlayers];
}
}];
}
弄清楚了! 我需要在邀請處理程序中調用- (void)matchForInvite:(GKInvite *)invite completionHandler:(void (^)(GKMatch *match, NSError *error))completionHandler
,以便兩個玩家都具有相同的比賽數據。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.