diff --git a/FullStackCodingBot/FullStackCodingBot.xcodeproj/project.pbxproj b/FullStackCodingBot/FullStackCodingBot.xcodeproj/project.pbxproj index 64a2b49..e6de1f2 100644 --- a/FullStackCodingBot/FullStackCodingBot.xcodeproj/project.pbxproj +++ b/FullStackCodingBot/FullStackCodingBot.xcodeproj/project.pbxproj @@ -21,6 +21,9 @@ 71307AB126A53C7B00C3191F /* AlertMessage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 71307AB026A53C7B00C3191F /* AlertMessage.swift */; }; 71307AB926A5437C00C3191F /* StorageTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 71307AB826A5437C00C3191F /* StorageTest.swift */; }; 71307AC126A5461700C3191F /* Unit.swift in Sources */ = {isa = PBXBuildFile; fileRef = E45B0AC82692F9CF006FDE3D /* Unit.swift */; }; + 7130B74026FEF8FD00DE90F3 /* LoginManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7130B73F26FEF8FD00DE90F3 /* LoginManager.swift */; }; + 7130B74426FEFC4700DE90F3 /* LoginManagerType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7130B74326FEFC4700DE90F3 /* LoginManagerType.swift */; }; + 7130B74626FEFCDA00DE90F3 /* LoginResult.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7130B74526FEFCDA00DE90F3 /* LoginResult.swift */; }; 71310C2C26AA596B00733361 /* CoreDataStorage.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 71310C2A26AA596B00733361 /* CoreDataStorage.xcdatamodeld */; }; 71310C2D26AA596B00733361 /* CoreDataStorage.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = 71310C2A26AA596B00733361 /* CoreDataStorage.xcdatamodeld */; }; 715A83EE269FE96300C9CEFF /* StoryboardType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 715A83ED269FE96300C9CEFF /* StoryboardType.swift */; }; @@ -180,6 +183,9 @@ 71307AB626A5437C00C3191F /* Full StackTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "Full StackTests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; 71307AB826A5437C00C3191F /* StorageTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StorageTest.swift; sourceTree = ""; }; 71307ABA26A5437C00C3191F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 7130B73F26FEF8FD00DE90F3 /* LoginManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginManager.swift; sourceTree = ""; }; + 7130B74326FEFC4700DE90F3 /* LoginManagerType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginManagerType.swift; sourceTree = ""; }; + 7130B74526FEFCDA00DE90F3 /* LoginResult.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginResult.swift; sourceTree = ""; }; 71310C2B26AA596B00733361 /* CoreDataStorage.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = CoreDataStorage.xcdatamodel; sourceTree = ""; }; 715A83ED269FE96300C9CEFF /* StoryboardType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StoryboardType.swift; sourceTree = ""; }; 715C1C9326BCF9FF0025C681 /* StoryViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StoryViewController.swift; sourceTree = ""; }; @@ -350,12 +356,23 @@ path = "Full StackTests"; sourceTree = ""; }; + 7130B73E26FEF8F100DE90F3 /* LoginManager */ = { + isa = PBXGroup; + children = ( + 7130B73F26FEF8FD00DE90F3 /* LoginManager.swift */, + 7130B74326FEFC4700DE90F3 /* LoginManagerType.swift */, + 7130B74526FEFCDA00DE90F3 /* LoginResult.swift */, + ); + path = LoginManager; + sourceTree = ""; + }; 715BB20426943CD100286B31 /* Service */ = { isa = PBXGroup; children = ( - E4336F6426F08A8D0049A5D8 /* Storage */, - 717EAD3B26A656E200E0CDB7 /* GameLogic */, + 7130B73E26FEF8F100DE90F3 /* LoginManager */, 718F224726C377AA00B2648C /* ErrorManager */, + 717EAD3B26A656E200E0CDB7 /* GameLogic */, + E4336F6426F08A8D0049A5D8 /* Storage */, ); path = Service; sourceTree = ""; @@ -1062,6 +1079,7 @@ 7164BFD2269679C6009769E4 /* MainItemView.swift in Sources */, E4150E9726B8F3E00041DD32 /* TypeWriterView.swift in Sources */, 71310C2C26AA596B00733361 /* CoreDataStorage.xcdatamodeld in Sources */, + 7130B74426FEFC4700DE90F3 /* LoginManagerType.swift in Sources */, E4BF710526AFD45A00E8645F /* TimeManagerType.swift in Sources */, E4336F5F26F083840049A5D8 /* BackUpCenterType.swift in Sources */, 710D0D4F2693F6E500244A16 /* ItemCell.swift in Sources */, @@ -1124,6 +1142,7 @@ E4DF614126A92CE00061F6E9 /* ShopItem.swift in Sources */, E4F4304426C4F8F500F046E9 /* GameStoryManager.swift in Sources */, E4F4304626CA2E4500F046E9 /* UnitInfo.swift in Sources */, + 7130B74626FEFCDA00DE90F3 /* LoginResult.swift in Sources */, E4BF713B26B7D2CC00E8645F /* SingleSoundEffectStation.swift in Sources */, E4D7C6422693E7B200D58BA2 /* MainViewController.swift in Sources */, E4150EA126BE44BD0041DD32 /* FullImageStoryView.swift in Sources */, @@ -1141,6 +1160,7 @@ 71E91E1726BA33190016386E /* Extension.swift in Sources */, 7170CD4526B266BE00F03248 /* VersionErrorViewController.swift in Sources */, 719D0D9026F1863200913BBE /* MainScene.swift in Sources */, + 7130B74026FEF8FD00DE90F3 /* LoginManager.swift in Sources */, E4CA08B926A8287B00AA6F03 /* Font.swift in Sources */, E4BF710B26B1324500E8645F /* ReadyView.swift in Sources */, 71DF64B92692C13A00557693 /* ShopViewController.swift in Sources */, diff --git a/FullStackCodingBot/FullStackCodingBot/Service/LoginManager/LoginManager.swift b/FullStackCodingBot/FullStackCodingBot/Service/LoginManager/LoginManager.swift new file mode 100644 index 0000000..edc368c --- /dev/null +++ b/FullStackCodingBot/FullStackCodingBot/Service/LoginManager/LoginManager.swift @@ -0,0 +1,54 @@ +import Foundation +import RxSwift +import GameKit +import FirebaseAuth + +final class LoginManager: NSObject, LoginManagerType { + + func getLoginResult() -> Observable { + Observable.create { observer in + var result = LoginResult() + GKLocalPlayer.local.authenticateHandler = { gcViewController, error in + + if let gcViewController = gcViewController { + result.gameVC = gcViewController + observer.onNext(result) + + } else if let error = error { + observer.onError(error) + + } else { + GameCenterAuthProvider.getCredential { credential, error in + + if let error = error { + observer.onError(error) + } + + guard let credential = credential else { + return + } + + Auth.auth().signIn(with: credential) { user, error in + if let error = error { + observer.onError(error) + } + + if let user = user { + result.uuid = user.user.uid + observer.onNext(result) + observer.onCompleted() + } + } + } + } + } + return Disposables.create() + } + } +} + +extension LoginManager: GKGameCenterControllerDelegate { + + func gameCenterViewControllerDidFinish(_ gameCenterViewController: GKGameCenterViewController) { + } +} diff --git a/FullStackCodingBot/FullStackCodingBot/Service/LoginManager/LoginManagerType.swift b/FullStackCodingBot/FullStackCodingBot/Service/LoginManager/LoginManagerType.swift new file mode 100644 index 0000000..7f00fce --- /dev/null +++ b/FullStackCodingBot/FullStackCodingBot/Service/LoginManager/LoginManagerType.swift @@ -0,0 +1,8 @@ +import Foundation +import RxSwift +import GameKit + +protocol LoginManagerType { + func getLoginResult() -> Observable +} + diff --git a/FullStackCodingBot/FullStackCodingBot/Service/LoginManager/LoginResult.swift b/FullStackCodingBot/FullStackCodingBot/Service/LoginManager/LoginResult.swift new file mode 100644 index 0000000..6f18bd2 --- /dev/null +++ b/FullStackCodingBot/FullStackCodingBot/Service/LoginManager/LoginResult.swift @@ -0,0 +1,6 @@ +import UIKit + +struct LoginResult { + var gameVC: UIViewController? + var uuid: String? +}