IOS GAME KIT - Where do I find pending invitations? GKInvite or AKA how do I accept programmatically an invitation?

醉酒当歌 提交于 2021-01-29 09:39:18

问题


As many others I am trying to figure out how gamekit works. At the moment I am able to invite a friend and accept it. But what I am not able to do is to 'catch' incoming invites, if the player missed the notification how can I present missed invitations to the player? Assuming the other side will wait of course to get connected.

I simply want to offer the user a way to accept a pending invitation after the notification is gone.


Scenario :

User 1 > sends invite to User 2

User 2 > was too late and missed the notification

User 1 > still waiting for User 2 to accept

User 2 > can't find the pending invitation anywhere


what I have so far and what I have tried:

This below doesnt help me.

func player(_ player: GKPlayer, didRequestMatchWithRecipients recipientPlayers: [GKPlayer])

This below doesn't contain the info I am looking for

https://developer.apple.com/documentation/gamekit/gklocalplayerlistener

This below only talks about player didAccept method AND didRequestMatchWithRecipients but the latter doesn't respond to incoming invitations.

https://developer.apple.com/documentation/gamekit/gkinviteeventlistener

Code Block 
   func player(_ player: GKPlayer, didAccept invite: GKInvite) {
        pendingInvite = invite
        print("invite = \(invite)")
        GKMatchmaker.shared().match (for: invite, completionHandler: {
            (InvitedMatch, error) in
            if error != nil {
                if let description = error?.localizedDescription {
                    print("Error creating match from invitation: \(description)")
                }
            } else {
                print ( "NO ERROR")
                self.update(with: InvitedMatch)
            }
        })
    }
    func update(with match: GKMatch?) {
        self.multiplayerMatch = match
        self.multiplayerMatch?.delegate = self
        if !multiplayerMatchStarted && multiplayerMatch?.expectedPlayerCount == 0 {
            print ("Ready to start the match MatchMaker")
            delegate?.matchStarted() 
        } else {
            print ("no players")
        }
    }

来源:https://stackoverflow.com/questions/62685965/ios-game-kit-where-do-i-find-pending-invitations-gkinvite-or-aka-how-do-i-acc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!