首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >传入的GameCenter邀请不包含播放器

传入的GameCenter邀请不包含播放器
EN

Stack Overflow用户
提问于 2020-06-07 00:33:47
回答 1查看 46关注 0票数 1

我正在尝试让我的游戏允许一个设备(iPhone)使用GameCenter邀请朋友玩(iPad)。我使用的是标准/默认的MatchMaker接口。iPhone向iPad发送邀请,后者提供通知。

当我按下这个通知时,iPad的‘player(GKPlayer,didAccept: GKInvite)’例程就会被调用。

代码语言:javascript
复制
  @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()
      }
    })
  }

输出:

代码语言:javascript
复制
        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代码:

代码语言:javascript
复制
  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 (邀请函的接收者)看到/包含球员呢?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-06-07 22:16:07

在player(GKPlayer,invite: GKInvite)方法中,通过

让mmvc = GKMatchmakerViewController(invite: invite!)

然后呈现出来:

viewController.present(mmvc!,动画:真,完成:空)

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62234754

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档