All Projects → SwiftPackageRepository → GameKitUI.swift

SwiftPackageRepository / GameKitUI.swift

Licence: MIT license
GameKit (GameCenter) for SwiftUI

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to GameKitUI.swift

SwiftUIDemo
A demo app showing you how to build a table view and navigation interface with SwiftUI
Stars: ✭ 26 (-10.34%)
Mutual labels:  swiftui, swift5
BottomSheet
A sliding Sheet from the bottom of the Screen with 3 States build with SwiftUI.
Stars: ✭ 597 (+1958.62%)
Mutual labels:  swiftui, swift5
Windows11
💻 Windows 11 in SwiftUI.
Stars: ✭ 177 (+510.34%)
Mutual labels:  swiftui, swift5
NYTimes-iOS
🗽 NY Times is an Minimal News 🗞 iOS app 📱 built to describe the use of SwiftSoup and CoreData with SwiftUI🔥
Stars: ✭ 152 (+424.14%)
Mutual labels:  swiftui, swift5
StoreHelper
Implementing and testing In-App Purchases with StoreKit2 and StoreHelper in Xcode 13, Swift 5.5, SwiftUI, iOS 15 and macOS 12.
Stars: ✭ 158 (+444.83%)
Mutual labels:  swiftui, swift5
StoryboardPreviewsBySwiftUI
Introduce how to make the Storyboard file and Xib file correspond to the preview function by SwiftUI.
Stars: ✭ 35 (+20.69%)
Mutual labels:  swiftui, swift5
QuoteKit
A framework to use the free APIs provided by https://quotable.io
Stars: ✭ 17 (-41.38%)
Mutual labels:  swiftui, swift5
OnlySwitch
⚙️ All-in-One menu bar app, hide 💻MacBook Pro's notch, dark mode, AirPods, Shortcuts
Stars: ✭ 1,288 (+4341.38%)
Mutual labels:  swiftui, swift5
Harbour
Docker/Portainer management app for iOS
Stars: ✭ 210 (+624.14%)
Mutual labels:  swiftui, swift5
LongWeekend-iOS
🏖📱 LongWeekend is iOS Application that supports checking long weekends when taking a vacation in Japan
Stars: ✭ 19 (-34.48%)
Mutual labels:  swiftui, swift5
ACarousel
A carousel view for SwiftUI | SwiftUI 旋转木马效果
Stars: ✭ 124 (+327.59%)
Mutual labels:  swiftui, swift5
iOS-SwiftUI-Firebase-Login-Example
Complete Sign up and Sign in Process for iOS SwiftUI - using Firebase Email and Password Authentication.
Stars: ✭ 37 (+27.59%)
Mutual labels:  swiftui, swift5
Swipeable-View
Simple editActionsForRowAt functionality, written on SWIFTUI
Stars: ✭ 37 (+27.59%)
Mutual labels:  swiftui, swift5
Swiftwebui
A demo implementation of SwiftUI for the Web
Stars: ✭ 3,663 (+12531.03%)
Mutual labels:  swiftui, swift5
SwiftUI-Tooltip
Easy Tooltip for your SwiftUI Project
Stars: ✭ 130 (+348.28%)
Mutual labels:  swiftui, swift5
JewelCase
This is the source code for JewelCase, a sample app demonstrating how to use SwiftUI and Firebase together. This slide deck discusses the architecture of the app: https://www.slideshare.net/peterfriese/building-swiftui-apps-with-firebase
Stars: ✭ 42 (+44.83%)
Mutual labels:  swiftui, swift5
SwiftUI-Currency-Converter
Currency Converter project coded by SwiftUI and Swift5
Stars: ✭ 56 (+93.1%)
Mutual labels:  swiftui, swift5
Shift
Light-weight EventKit wrapper.
Stars: ✭ 31 (+6.9%)
Mutual labels:  swiftui, swift5
stinsen
Coordinators in SwiftUI. Simple, powerful and elegant.
Stars: ✭ 563 (+1841.38%)
Mutual labels:  swiftui, swift5
SimpleToast
SimpleToast is a simple, lightweight, flexible and easy to use library to show toasts / popup notifications inside iOS or MacOS applications in SwiftUI. Because of the flexibility to show any content it is also possible to use the library for showing simple modals.
Stars: ✭ 131 (+351.72%)
Mutual labels:  swiftui, swift5

 

GameKitUI.swift

GameKit (GameCenter) helper for SwiftUI

GameKitUI is created and maintaned with ❥ by Sascha Muellner.


Swift codecov License Version SPM compatible README

What?

This is a Swift package with support for iOS 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/SwiftPackageRepository/GameKitUI.swift.git'

How to use?

Views

GameCenter Authentication

To authenticate the player with GameCenter just show the authentication view GKAuthenticationView.

import SwiftUI
import GameKitUI

struct ContentView: View {
	var body: some View {
		GKAuthenticationView { (state) in
			switch state {
			    case .started:
			    	print("Authentication Started")
			    	break
			    case .failed:
			    	print("Failed")
			    	break
			    case .deauthenticated:
					print("Deauthenticated")
			      	break
			    case .succeeded:
			    	break
			}
		} failed: { (error) in
			print("Failed: \(error.localizedDescription)")
		} authenticated: { (playerName) in
			print("Hello \(playerName)")
		}
	}
}

GameKit Invite

Invites created by a GameKit MatchMaker or TurnBasedMatchmaker can be handled using a GKMatchMakerView.

import SwiftUI
import GameKitUI

struct ContentView: View {
    var body: some View {
        GKInviteView(
            invite: GKInvite()
        ) {
        } failed: { (error) in
            print("Invitation Failed: \(error.localizedDescription)")
        } started: { (match) in
            print("Match Started")
        }
    }
}

GameKit MatchMaker

Match making for a live match can be initiated via the GKMatchMakerView.

import SwiftUI
import GameKitUI

struct ContentView: View {
	var body: some View {
		GKMatchMakerView(
                    minPlayers: 2,
                    maxPlayers: 4,
                    inviteMessage: "Let us play together!"
                ) {
                    print("Player Canceled")
                } failed: { (error) in
                    print("Match Making Failed: \(error.localizedDescription)")
                } started: { (match) in
                    print("Match Started")
                }
	}
}

GameKit TurnBasedMatchmaker

To start a turn based match use GKTurnBasedMatchmakerView.

import SwiftUI
import GameKitUI

struct ContentView: View {
	var body: some View {
		GKTurnBasedMatchmakerView(
                    minPlayers: 2,
                    maxPlayers: 4,
                    inviteMessage: "Let us play together!"
                ) {
                    print("Player Canceled")
                } failed: { (error) in
                    print("Match Making Failed: \(error.localizedDescription)")
                } started: { (match) in
                    print("Match Started")
                }
	}
}

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.

import SwiftUI
import GameKitUI

class ViewModel: ObservableObject {

    @Published public var gkInvite: GKInvite?
    @Published public var gkMatch: GKMatch?

    private var cancellableInvite: AnyCancellable?
    private var cancellableMatch: AnyCancellable?
    private var cancellableLocalPlayer: AnyCancellable?

    public init() {
        self.cancellableInvite = GKMatchManager
            .shared
            .invite
            .sink { (invite) in
                self.gkInvite = invite.gkInvite
        }
        self.cancellableMatch = GKMatchManager
            .shared
            .match
            .sink { (match) in
                self.gkMatch = match.gkMatch
        }
        self.cancellableLocalPlayer = GKMatchManager
            .shared
            .localPlayer
            .sink { (localPlayer) in
                // current GKLocalPlayer.local
        }
    }
    
    deinit() {
        self.cancellableInvite?.cancel()
        self.cancellableMatch?.cancel()
        self.cancellableLocalPlayer?.cancel()
    }
}

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:

// Configuration settings file format documentation can be found at:
// https://help.apple.com/xcode/#/dev745c5c974

XCCONFIG_DEVELOPMENT_TEAM = 9988XX7D42 // YOUR DEVELOPMENT TEAM ID
XCCONFIG_BUNDLE_ID = com.yourcompany.ProductName // A BUNDLE ID WITH SUPPORT FOR THE GAMECENTER CAPABILITY

Then open the GKMatchMaker.xcodeproj and run it on as many real hardware devices to test the GameKit match making.

Documentation

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].