|
How do I inject GKMatch into SwiftUI view similar to this example https://www.hackingwithswift.com/books/ios-swiftui/using-coordinators-to-manage-swiftui-view-controllers ? I am building a multiplayer game in SwiftUI and I had to use UIViewControllerRepresentable to wrap the GKMatchMakerViewController into SwiftUI, however, I face a little problem where GKMatchDelegate methods are not being called. I have detected that it is happening because I dismiss the viewcontroller on didFindMatch method. I have tried to follow the above linked example, but I am not sure how I can put the GKMatch into a SwiftUI view as twoStraws did with the image in the example like so
Can someone tell me what I can do? I tried my version like below.
This is the code I have to load the GKMatch: multiPlayerMatch into my view but it doesn't solve my problem. Which view can take in the GKMatch type? Below is how my wrapper struct looks like.
|
|
@The-Heymann: Hi, I am currently working on the same topic and basically the best way I found was to wrap the GKViewControllers in another UIViewController that cares for the display of the GKViewController. The decision is based on the fact that the GKTurnBasedMatchmakerViewController and the GKMatchmakerViewController can result in an optional during initilization. Where as for the authentication the GKAuthenticationViewController is only created conditionally any only if the player is not already authenticated. At the moment authentication and match making is working for me in custom SwiftUI views. If you are interested on how I did achive it take a look at the current state here: https://github.com/SwiftPackageRepository/GameKitUI.swift And as always any help is welcome :) and greatly appreciated. |
SPONSORED Get accurate app localizations in minutes using AI. Choose your languages & receive translations for 40+ markets!
Sponsor Hacking with Swift and reach the world's largest Swift community!
This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.