Skip to content

Commit 3aaa0ae

Browse files
authored
Merge pull request #9 from SwiftPackageRepository/How-to-accept-invitations-#7
Reworked authentication process
2 parents e1f7c55 + a0b0e34 commit 3aaa0ae

30 files changed

+1635
-433
lines changed

Examples/GKMatchMaker/GKMatchMaker.xcodeproj/project.pbxproj

Lines changed: 41 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,35 @@
99
/* Begin PBXBuildFile section */
1010
1507A0BD25E410CA006DDBFC /* GKMatchMakerApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1507A0BC25E410CA006DDBFC /* GKMatchMakerApp.swift */; };
1111
1507A0BE25E410CA006DDBFC /* GKMatchMakerApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1507A0BC25E410CA006DDBFC /* GKMatchMakerApp.swift */; };
12-
1507A0C625E419E5006DDBFC /* SinglePlayerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1507A0C525E419E5006DDBFC /* SinglePlayerView.swift */; };
13-
1507A0C725E419E5006DDBFC /* SinglePlayerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1507A0C525E419E5006DDBFC /* SinglePlayerView.swift */; };
12+
1507A0C625E419E5006DDBFC /* AuthenticationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1507A0C525E419E5006DDBFC /* AuthenticationView.swift */; };
13+
1507A0C725E419E5006DDBFC /* AuthenticationView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1507A0C525E419E5006DDBFC /* AuthenticationView.swift */; };
1414
151CAAA225E39837002A7FDC /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 151CAA8D25E39837002A7FDC /* Assets.xcassets */; };
1515
151CAAA325E39837002A7FDC /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 151CAA8D25E39837002A7FDC /* Assets.xcassets */; };
1616
151CAAD125E39928002A7FDC /* Config.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = 151CAAD025E39928002A7FDC /* Config.xcconfig */; };
1717
151CAAD225E39928002A7FDC /* Config.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = 151CAAD025E39928002A7FDC /* Config.xcconfig */; };
1818
151CAAD725E399D6002A7FDC /* GameKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 151CAAD625E399D6002A7FDC /* GameKit.framework */; };
19+
151D895F2602660B00979718 /* MatchView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 151D895E2602660B00979718 /* MatchView.swift */; };
20+
151D89602602660B00979718 /* MatchView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 151D895E2602660B00979718 /* MatchView.swift */; };
1921
151F91ED25E42EC60015DD88 /* PrimaryButtonModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 151F91EC25E42EC60015DD88 /* PrimaryButtonModifier.swift */; };
2022
151F91EE25E42EC60015DD88 /* PrimaryButtonModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 151F91EC25E42EC60015DD88 /* PrimaryButtonModifier.swift */; };
23+
151F91F925E4EC070015DD88 /* AuthenticationViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 151F91F825E4EC070015DD88 /* AuthenticationViewModel.swift */; };
24+
151F91FA25E4EC070015DD88 /* AuthenticationViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 151F91F825E4EC070015DD88 /* AuthenticationViewModel.swift */; };
25+
152736842607D0740068853D /* MatchMakingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 152736812607D0730068853D /* MatchMakingView.swift */; };
26+
152736882607D07C0068853D /* MatchMakingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 152736812607D0730068853D /* MatchMakingView.swift */; };
2127
15A6F7D725E39B7D00FE5387 /* GameKitUI in Frameworks */ = {isa = PBXBuildFile; productRef = 15A6F7D625E39B7D00FE5387 /* GameKitUI */; };
2228
15A6F7D925E39B8300FE5387 /* GameKitUI in Frameworks */ = {isa = PBXBuildFile; productRef = 15A6F7D825E39B8300FE5387 /* GameKitUI */; };
2329
15A6F7DB25E39B8F00FE5387 /* GameKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 15A6F7DA25E39B8F00FE5387 /* GameKit.framework */; };
2430
15A6F7E225E39BC100FE5387 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15A6F7DF25E39BC100FE5387 /* ContentView.swift */; };
2531
15A6F7E325E39BC100FE5387 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15A6F7DF25E39BC100FE5387 /* ContentView.swift */; };
2632
15A6F7F125E39E0500FE5387 /* MatchMakingViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15A6F7F025E39E0500FE5387 /* MatchMakingViewModel.swift */; };
2733
15A6F7F225E39E0500FE5387 /* MatchMakingViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15A6F7F025E39E0500FE5387 /* MatchMakingViewModel.swift */; };
28-
15A6F7F625E39E5300FE5387 /* MatchMakingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15A6F7F525E39E5300FE5387 /* MatchMakingView.swift */; };
29-
15A6F7F725E39E5300FE5387 /* MatchMakingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15A6F7F525E39E5300FE5387 /* MatchMakingView.swift */; };
34+
15F85DE4260272CF0009A734 /* GKMatchMakerAppModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15F85DE3260272CF0009A734 /* GKMatchMakerAppModel.swift */; };
35+
15F85DE7260272D20009A734 /* GKMatchMakerAppModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 15F85DE3260272CF0009A734 /* GKMatchMakerAppModel.swift */; };
3036
/* End PBXBuildFile section */
3137

3238
/* Begin PBXFileReference section */
3339
1507A0BC25E410CA006DDBFC /* GKMatchMakerApp.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GKMatchMakerApp.swift; sourceTree = "<group>"; };
34-
1507A0C525E419E5006DDBFC /* SinglePlayerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SinglePlayerView.swift; sourceTree = "<group>"; };
40+
1507A0C525E419E5006DDBFC /* AuthenticationView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthenticationView.swift; sourceTree = "<group>"; };
3541
151CAA8D25E39837002A7FDC /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
3642
151CAA9225E39837002A7FDC /* GKMatchMaker.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = GKMatchMaker.app; sourceTree = BUILT_PRODUCTS_DIR; };
3743
151CAA9525E39837002A7FDC /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
@@ -41,11 +47,14 @@
4147
151CAAD025E39928002A7FDC /* Config.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = Config.xcconfig; sourceTree = "<group>"; };
4248
151CAAD625E399D6002A7FDC /* GameKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = GameKit.framework; path = Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.4.sdk/System/Library/Frameworks/GameKit.framework; sourceTree = DEVELOPER_DIR; };
4349
151CAAD825E399DF002A7FDC /* GameKitUI.swift */ = {isa = PBXFileReference; lastKnownFileType = folder; name = GameKitUI.swift; path = ../..; sourceTree = "<group>"; };
50+
151D895E2602660B00979718 /* MatchView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MatchView.swift; sourceTree = "<group>"; };
4451
151F91EC25E42EC60015DD88 /* PrimaryButtonModifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PrimaryButtonModifier.swift; sourceTree = "<group>"; };
52+
151F91F825E4EC070015DD88 /* AuthenticationViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthenticationViewModel.swift; sourceTree = "<group>"; };
53+
152736812607D0730068853D /* MatchMakingView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MatchMakingView.swift; sourceTree = "<group>"; };
4554
15A6F7DA25E39B8F00FE5387 /* GameKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = GameKit.framework; path = System/Library/Frameworks/GameKit.framework; sourceTree = SDKROOT; };
4655
15A6F7DF25E39BC100FE5387 /* ContentView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
4756
15A6F7F025E39E0500FE5387 /* MatchMakingViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MatchMakingViewModel.swift; sourceTree = "<group>"; };
48-
15A6F7F525E39E5300FE5387 /* MatchMakingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MatchMakingView.swift; sourceTree = "<group>"; };
57+
15F85DE3260272CF0009A734 /* GKMatchMakerAppModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GKMatchMakerAppModel.swift; sourceTree = "<group>"; };
4958
/* End PBXFileReference section */
5059

5160
/* Begin PBXFrameworksBuildPhase section */
@@ -138,10 +147,18 @@
138147
path = Modifiers;
139148
sourceTree = "<group>";
140149
};
150+
151F91F725E4EBEE0015DD88 /* Authentication */ = {
151+
isa = PBXGroup;
152+
children = (
153+
151F91F825E4EC070015DD88 /* AuthenticationViewModel.swift */,
154+
);
155+
path = Authentication;
156+
sourceTree = "<group>";
157+
};
141158
15A6F7DE25E39BC100FE5387 /* Views */ = {
142159
isa = PBXGroup;
143160
children = (
144-
15A6F7FD25E39F8700FE5387 /* SinglePlayer */,
161+
15A6F7FD25E39F8700FE5387 /* Authentication */,
145162
15A6F7FC25E39F7D00FE5387 /* MultiPlayer */,
146163
15A6F7DF25E39BC100FE5387 /* ContentView.swift */,
147164
);
@@ -151,7 +168,8 @@
151168
15A6F7E025E39BC100FE5387 /* ViewModels */ = {
152169
isa = PBXGroup;
153170
children = (
154-
15A6F7FB25E39F7200FE5387 /* SinglePlayer */,
171+
15F85DE3260272CF0009A734 /* GKMatchMakerAppModel.swift */,
172+
151F91F725E4EBEE0015DD88 /* Authentication */,
155173
15A6F7FA25E39F6200FE5387 /* MultiPlayer */,
156174
);
157175
path = ViewModels;
@@ -165,27 +183,21 @@
165183
path = MultiPlayer;
166184
sourceTree = "<group>";
167185
};
168-
15A6F7FB25E39F7200FE5387 /* SinglePlayer */ = {
169-
isa = PBXGroup;
170-
children = (
171-
);
172-
path = SinglePlayer;
173-
sourceTree = "<group>";
174-
};
175186
15A6F7FC25E39F7D00FE5387 /* MultiPlayer */ = {
176187
isa = PBXGroup;
177188
children = (
178-
15A6F7F525E39E5300FE5387 /* MatchMakingView.swift */,
189+
152736812607D0730068853D /* MatchMakingView.swift */,
190+
151D895E2602660B00979718 /* MatchView.swift */,
179191
);
180192
path = MultiPlayer;
181193
sourceTree = "<group>";
182194
};
183-
15A6F7FD25E39F8700FE5387 /* SinglePlayer */ = {
195+
15A6F7FD25E39F8700FE5387 /* Authentication */ = {
184196
isa = PBXGroup;
185197
children = (
186-
1507A0C525E419E5006DDBFC /* SinglePlayerView.swift */,
198+
1507A0C525E419E5006DDBFC /* AuthenticationView.swift */,
187199
);
188-
path = SinglePlayer;
200+
path = Authentication;
189201
sourceTree = "<group>";
190202
};
191203
/* End PBXGroup section */
@@ -293,9 +305,12 @@
293305
isa = PBXSourcesBuildPhase;
294306
buildActionMask = 2147483647;
295307
files = (
296-
1507A0C625E419E5006DDBFC /* SinglePlayerView.swift in Sources */,
297-
15A6F7F625E39E5300FE5387 /* MatchMakingView.swift in Sources */,
308+
15F85DE4260272CF0009A734 /* GKMatchMakerAppModel.swift in Sources */,
309+
1507A0C625E419E5006DDBFC /* AuthenticationView.swift in Sources */,
310+
151F91F925E4EC070015DD88 /* AuthenticationViewModel.swift in Sources */,
311+
151D895F2602660B00979718 /* MatchView.swift in Sources */,
298312
15A6F7E225E39BC100FE5387 /* ContentView.swift in Sources */,
313+
152736842607D0740068853D /* MatchMakingView.swift in Sources */,
299314
151F91ED25E42EC60015DD88 /* PrimaryButtonModifier.swift in Sources */,
300315
1507A0BD25E410CA006DDBFC /* GKMatchMakerApp.swift in Sources */,
301316
15A6F7F125E39E0500FE5387 /* MatchMakingViewModel.swift in Sources */,
@@ -306,9 +321,12 @@
306321
isa = PBXSourcesBuildPhase;
307322
buildActionMask = 2147483647;
308323
files = (
309-
1507A0C725E419E5006DDBFC /* SinglePlayerView.swift in Sources */,
310-
15A6F7F725E39E5300FE5387 /* MatchMakingView.swift in Sources */,
324+
15F85DE7260272D20009A734 /* GKMatchMakerAppModel.swift in Sources */,
325+
1507A0C725E419E5006DDBFC /* AuthenticationView.swift in Sources */,
326+
151F91FA25E4EC070015DD88 /* AuthenticationViewModel.swift in Sources */,
327+
151D89602602660B00979718 /* MatchView.swift in Sources */,
311328
15A6F7E325E39BC100FE5387 /* ContentView.swift in Sources */,
329+
152736882607D07C0068853D /* MatchMakingView.swift in Sources */,
312330
151F91EE25E42EC60015DD88 /* PrimaryButtonModifier.swift in Sources */,
313331
1507A0BE25E410CA006DDBFC /* GKMatchMakerApp.swift in Sources */,
314332
15A6F7F225E39E0500FE5387 /* MatchMakingViewModel.swift in Sources */,
Lines changed: 57 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,66 @@
1-
//
2-
// GKMatchMakerApp.swift
3-
// Shared
4-
//
5-
// Created by smuellner on 22.02.21.
6-
//
1+
///
2+
/// MIT License
3+
///
4+
/// Copyright (c) 2020 Sascha Müllner
5+
///
6+
/// Permission is hereby granted, free of charge, to any person obtaining a copy
7+
/// of this software and associated documentation files (the "Software"), to deal
8+
/// in the Software without restriction, including without limitation the rights
9+
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
/// copies of the Software, and to permit persons to whom the Software is
11+
/// furnished to do so, subject to the following conditions:
12+
///
13+
/// The above copyright notice and this permission notice shall be included in all
14+
/// copies or substantial portions of the Software.
15+
///
16+
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
/// SOFTWARE.
23+
///
24+
/// Created by Sascha Müllner on 24.11.20.
725

826
import SwiftUI
27+
import GameKit
28+
import GameKitUI
929

1030
@main
1131
struct GKMatchMakerApp: App {
12-
var body: some Scene {
32+
@ObservedObject var viewModel = GKMatchMakerAppModel()
33+
34+
public var body: some Scene {
1335
WindowGroup {
14-
ContentView()
36+
ZStack {
37+
ContentView()
38+
.alert(isPresented: self.$viewModel.showAlert) {
39+
Alert(title: Text(self.viewModel.alertTitle),
40+
message: Text(self.viewModel.alertMessage),
41+
dismissButton: .default(Text("Ok")))
42+
}
43+
if self.viewModel.showAuthentication {
44+
GKAuthenticationView { (error) in
45+
self.viewModel.showAlert(title: "Authentication Failed", message: error.localizedDescription)
46+
} authenticated: { (player) in
47+
self.viewModel.showAuthentication = false
48+
}
49+
} else if self.viewModel.showInvite {
50+
GKInviteView(
51+
invite: self.viewModel.invite.gkInvite!
52+
) {
53+
} failed: { (error) in
54+
self.viewModel.showAlert(title: "Invitation Failed", message: error.localizedDescription)
55+
} started: { (gkMatch) in
56+
self.viewModel.showInvite = false
57+
self.viewModel.gkMatch = gkMatch
58+
}
59+
} else if self.viewModel.showMatch,
60+
let gkMatch = self.viewModel.gkMatch {
61+
MatchView(gkMatch)
62+
}
63+
}
1564
}
1665
}
1766
}

Examples/GKMatchMaker/Shared/Modifiers/PrimaryButtonModifier.swift

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,25 @@
11
///
2-
/// PrimaryButtonModifier.swift
3-
/// GKMatchMaker
2+
/// MIT License
3+
///
4+
/// Copyright (c) 2020 Sascha Müllner
5+
///
6+
/// Permission is hereby granted, free of charge, to any person obtaining a copy
7+
/// of this software and associated documentation files (the "Software"), to deal
8+
/// in the Software without restriction, including without limitation the rights
9+
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
/// copies of the Software, and to permit persons to whom the Software is
11+
/// furnished to do so, subject to the following conditions:
12+
///
13+
/// The above copyright notice and this permission notice shall be included in all
14+
/// copies or substantial portions of the Software.
15+
///
16+
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
/// SOFTWARE.
423
///
524
/// Created by Sascha Müllner on 22.02.21.
625
///
@@ -11,9 +30,9 @@ struct PrimaryButtonModifier: ViewModifier {
1130
func body(content: Content) -> some View {
1231
return content
1332
.font(.title)
14-
.padding(40)
33+
.padding(32)
1534
.background(Color("ButtonColor"))
16-
.cornerRadius(40)
35+
.cornerRadius(32)
1736
.foregroundColor(Color("ButtonTextColor"))
1837
}
1938
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
///
2+
/// MIT License
3+
///
4+
/// Copyright (c) 2020 Sascha Müllner
5+
///
6+
/// Permission is hereby granted, free of charge, to any person obtaining a copy
7+
/// of this software and associated documentation files (the "Software"), to deal
8+
/// in the Software without restriction, including without limitation the rights
9+
/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
/// copies of the Software, and to permit persons to whom the Software is
11+
/// furnished to do so, subject to the following conditions:
12+
///
13+
/// The above copyright notice and this permission notice shall be included in all
14+
/// copies or substantial portions of the Software.
15+
///
16+
/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
/// SOFTWARE.
23+
///
24+
/// Created by smuellner on 23.02.21.
25+
26+
27+
import Foundation
28+
import Combine
29+
30+
class AuthenticationViewModel: ObservableObject {
31+
32+
@Published public var showModal = false
33+
@Published public var showAlert = false
34+
@Published public var alertTitle: String = ""
35+
@Published public var alertMessage: String = ""
36+
@Published public var currentState: String = "Loading GameKit..."
37+
38+
public init() {
39+
}
40+
41+
public func load() {
42+
self.showAuthenticationModal()
43+
}
44+
45+
public func showAlert(title: String, message: String) {
46+
self.showAlert = true
47+
self.alertTitle = title
48+
self.alertMessage = message
49+
}
50+
51+
public func showAuthenticationModal() {
52+
self.showModal = true
53+
}
54+
}

0 commit comments

Comments
 (0)