I want to use GameCenter MatchMakerViewController
to invite friends to my Multiplayer Real-Time-Game. When inviting a friend he receives a link via iMessage with the invitation. When clicking on that link I want to handle the invitation, but right now I'm not sure how to do so.
In previous threads the inviteHandler was used to receive an event for an incoming invitation, but in the Apple Docs this method is marked as deprecated.
Reading through the docs I found this method, but I failed trying to implement it. Before putting more effort into the implementation I wanted to know if I am choosing the right approach for handling game center invitations? Does anybody know the right way after apple deprecated the inviteHandler
?
Thank you!
I was able to figure it out myself. There is no good answer to this question in Swift and the Apple Docs to this topic are more than confusing. Steps to make this work:
Implement [func player(_ player: GKPlayer, didAccept invite: GKInvite)][1]
in the class of your choice and tell the class to implement GKLocalPlayerListener
In the above mentioned method initialize the MatchmakingViewController
with the GKInvite
instance received from the method.
Try it. MatchmakingViewController will show up und start your game immediately.
For me it was quite hard to figure this out. Hope this post will help others.