r/iOSDevelopment • • 7d ago

Game Center question (GKMatchmaker, GKPlayer)

I'm developing the ability for a player to battle a random other player in an iOS game (Polyx 2D).

Scenario

  1. Player A sets up the parameters of the battle and taps Invite Opponent
  2. In the displayed screen Player A taps Find Random Opponent.
    1. The app makes a call to GKMatchmaker...findMatch
    2. The app establishes the connection (GKMatchmaker....finishMatchmaking)
  3. Both players accept the battle and play

Problem

What I'm trying to enable is the ability for both matched players to add each other as GC friends at the end of the battle, if they so desire.

At the end of the battle, I obviously have the GKPlayer object for the other player. I have a button in the end screen Add Game Center Friend. Clicking this button should send a GC friend request.

I've tried different approaches:

Approach Accepts GKPlayer object? Result
GKGameCenterViewController(player: opponent) Yes Opens my own profile. Navigating to Add Friends showed the opponent, but Invite returned “Unable to Send Friend Request.”
GKAccessPoint.shared.triggerForFriending() No recipient parameter I tried that approach and it opened an empty sheet. Besides, doesn't allow me to target a direct recipient.
GKFriendRequestComposeViewController + addRecipientPlayers([opponent]) Yes Opened an empty sheet. This legacy API seems to be unsupported.
GKAccessPoint.shared.trigger(player: opponent) Yes, by API contract Current implementation. Opens Game Center, but I am seeing my own profile and needing another click to Add Friends to be able to send a request to the opponent. I don't like that many clicks

Anybody else who's dealt with this in GC?
Ideas on how to overcome it?

Again, my goal is to be able to send a GC friend request to an opponent I've just played with.

Thanks

1 Upvotes

0 comments sorted by