GameKitUI.swift
GameKit (GameCenter) helper for SwiftUI
What?
This is a Swift package with support for iOS/macOS/tvOS that allows to use GameKit with SwiftUI.
Requirements
The latest version of GameKitUI requires:
- Swift 5+
- iOS 13+
- Xcode 11+
Installation
Swift Package Manager
Using SPM add the following to your dependencies
'GameKitUI', 'main', 'https://github.com/smuellner/GameKitUI.swift.git'
How to use?
Views
GameCenter Authentication
To authenticate the player with GameCenter just show the authentication view GKAuthenticationView.
GameKit Invite
Invites created by a GameKit MatchMaker or TurnBasedMatchmaker can be handled using a GKMatchMakerView.
GameKit MatchMaker
Match making for a live match can be initiated via the GKMatchMakerView.
GameKit TurnBasedMatchmaker
To start a turn based match use GKTurnBasedMatchmakerView.
GameKit Manager
GKMatchManager
GameKitUI views rely on a manager singelton GKMatchManager, which listens to GameKit state changes of the match making process.
Changes to the local player GKLocalPlayer, invites GKInvite or matches GKMatch can be observed using the provided public subjects CurrentValueSubject.
Examples
GKMatchMaker Example
The provided GKMatchMaker example, includes a full working SwiftUI solution for handling GameKit matchmaking.
Just copy the file Config.xcconfig-example to Config.xcconfig and add your development team ID for the variable XCCONFIG_DEVELOPMENT_TEAM and a valid Bundle ID with GameCenter support for XCCONFIG_BUNDLE_ID.
The Config.xcconfig should now look something like this:
Then open the GKMatchMaker.xcodeproj and run it on as many real hardware devices to test the GameKit match making.
GameKitUI is created and maintaned with ❥ by Sascha Muellner.