我正在尝试让我的游戏允许一个设备(iPhone)使用GameCenter邀请朋友玩(iPad)。我使用的是标准/默认的MatchMaker接口。iPhone向iPad发送邀请,后者提供通知。
当我按下这个通知时,iPad的‘player(GKPlayer,didAccept: GKInvite)’例程就会被调用。
@objc func player(_ playerMe: GKPlayer, didAccept invite: GKInvite) {
print("\n\n\t\tplayer \(playerMe.displayName)(\(playerMe.playerID)) did accept INVITE sent by \(invite.sender.displayName)(\(invite.sender.playerID))")
GKMatchmaker.shared().match(for: invite, completionHandler: {(InvitedMatch, error) in
print("\t\tplayers.count = \(InvitedMatch!.players.count)")
if error != nil {
print("INVITE ERROR: \(error.debugDescription)")
}
if InvitedMatch != nil {
print("\t\tSetting current match. (\(InvitedMatch.debugDescription))")
self.currentMatch = InvitedMatch
self.currentMatch?.delegate = self
// self.prepareMatch()
}
})
}输出:
player Me(G:25139341913) did accept INVITE sent by “-----”(G:12453976)
players.count = 0
Setting current match. (Optional(<GKMatch 0x282d39970 expected count: 1 seqnum: 0
G:12453976:unknown
reinvitedPlayers:(
)>))玩家数组为空!难道它不应该至少有邀请者在里面吗?‘expectedPlayerCount’正确地反映了2人matchRequest,其中1个玩家(邀请者)已经是参与者)
任何一端都没有调用“player(GKPlayer,didRequestMatchWithRecipients: GKPlayer)”。
因此,iPad不能访问球员来设置比赛,但是iPhone看到邀请被接受,有2名球员,然后继续。iPhone代码:
func matchmakerViewController(_ viewController: GKMatchmakerViewController, didFind match: GKMatch) {
print("\n\n\t\tMATCH FOUND\n\n")
viewController.dismiss(animated: true, completion: nil)
GKMatchmaker.shared().stopBrowsingForNearbyPlayers()
currentMatch = match
match.delegate = self
if Globals.gameState?.currentState is StateWaitingForMatch {
if currentMatch?.expectedPlayerCount == 0 {
prepareMatch()
}
}
}那么如何让iPad (邀请函的接收者)看到/包含球员呢?
发布于 2020-06-07 22:16:07
在player(GKPlayer,invite: GKInvite)方法中,通过
让mmvc = GKMatchmakerViewController(invite: invite!)
然后呈现出来:
viewController.present(mmvc!,动画:真,完成:空)
https://stackoverflow.com/questions/62234754
复制相似问题