Ios 传入的GameCenter邀请不包含任何玩家
我正在尝试让我的游戏允许1台设备(iPhone)使用GameCenter邀请朋友玩(iPad)。我使用的是标准/默认的媒人界面。iPhone向iPad发送邀请,iPad会发出通知 当我按下此通知时,iPad的“player(GKPlayer,didAccept:GKInvite)”例程确实会被调用Ios 传入的GameCenter邀请不包含任何玩家,ios,swift,game-center,Ios,Swift,Game Center,我正在尝试让我的游戏允许1台设备(iPhone)使用GameCenter邀请朋友玩(iPad)。我使用的是标准/默认的媒人界面。iPhone向iPad发送邀请,iPad会发出通知 当我按下此通知时,iPad的“player(GKPlayer,didAccept:GKInvite)”例程确实会被调用 @objc func player(_ playerMe: GKPlayer, didAccept invite: GKInvite) { print("\n\n\t\tplayer \(
@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:(
)>))
那么,如何让iPad(邀请的接收者)看到/包含玩家呢?在player(GKPlayer,invite:GKInvite)方法中,通过
让mmvc=GKMatchmakerViewController(invite:invite!)
然后展示:
viewController.present(mmvc!,动画:true,完成:nil)
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()
}
}
}