From 484c539cfbc8232361f282a4cd2a7124a415f21f Mon Sep 17 00:00:00 2001 From: kim-seonwoo Date: Thu, 11 Jan 2024 17:41:52 +0900 Subject: [PATCH 01/26] =?UTF-8?q?[Feat/#46]=20=EC=95=A0=ED=94=8C=EB=A1=9C?= =?UTF-8?q?=EA=B7=B8=EC=9D=B8=20=ED=83=80=EA=B2=9F=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HMH_iOS/HMH_iOS/HMH_iOS.entitlements | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/HMH_iOS/HMH_iOS/HMH_iOS.entitlements b/HMH_iOS/HMH_iOS/HMH_iOS.entitlements index e048c21..92f5bd8 100644 --- a/HMH_iOS/HMH_iOS/HMH_iOS.entitlements +++ b/HMH_iOS/HMH_iOS/HMH_iOS.entitlements @@ -2,6 +2,10 @@ + com.apple.developer.applesignin + + Default + com.apple.developer.family-controls From 754f0dc1bfc445be0c6fa05025ffbaf1b62da8ba Mon Sep 17 00:00:00 2001 From: kim-seonwoo Date: Thu, 11 Jan 2024 17:42:33 +0900 Subject: [PATCH 02/26] =?UTF-8?q?[Feat/#46]=20Login=20-=20=EB=A1=9C?= =?UTF-8?q?=EA=B7=B8=EC=9D=B8=20=EB=B7=B0=20=EC=BB=A8=ED=8A=B8=EB=A1=A4?= =?UTF-8?q?=EB=9F=AC=20=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ViewControllers/LoginViewController.swift | 96 ++++++++++++++++++- 1 file changed, 91 insertions(+), 5 deletions(-) diff --git a/HMH_iOS/HMH_iOS/Presentation/Login/ViewControllers/LoginViewController.swift b/HMH_iOS/HMH_iOS/Presentation/Login/ViewControllers/LoginViewController.swift index da57696..42a26ce 100644 --- a/HMH_iOS/HMH_iOS/Presentation/Login/ViewControllers/LoginViewController.swift +++ b/HMH_iOS/HMH_iOS/Presentation/Login/ViewControllers/LoginViewController.swift @@ -13,10 +13,33 @@ import AuthenticationServices final class LoginViewController: UIViewController { let authorizationButton = ASAuthorizationAppleIDButton(authorizationButtonType: .signIn, authorizationButtonStyle: .white) + func setAppleLoginButton() { + authorizationButton.addTarget(self, action: #selector(handleAuthorizationAppleIDButtonPress), for: .touchUpInside) + self.view.addSubview(authorizationButton) + authorizationButton.translatesAutoresizingMaskIntoConstraints = false + } + + @objc + func handleAuthorizationAppleIDButtonPress() { + let appleIDProvider = ASAuthorizationAppleIDProvider() + let request = appleIDProvider.createRequest() + request.requestedScopes = [.fullName, .email] + print(request, "๐Ÿ‘") + let authorizationController = ASAuthorizationController(authorizationRequests: [request]) + authorizationController.delegate = self + authorizationController.presentationContextProvider = self + authorizationController.performRequests() + } + + @objc func appleButtonTaped() { + print("tap") + } + let swipeView = OnboardingSwipeView() override func viewDidLoad() { super.viewDidLoad() + setAppleLoginButton() setUI() } @@ -43,11 +66,74 @@ final class LoginViewController: UIViewController { $0.height.equalTo(480) } } - - private func setAppleLoginButton() { - self.view.addSubview(authorizationButton) - authorizationButton.translatesAutoresizingMaskIntoConstraints = false - } } +extension LoginViewController: ASAuthorizationControllerDelegate, ASAuthorizationControllerPresentationContextProviding{ + func presentationAnchor(for controller: ASAuthorizationController) -> ASPresentationAnchor { + return self.view.window! + } + + func authorizationController(controller: ASAuthorizationController, didCompleteWithAuthorization authorization: ASAuthorization) { + //๋กœ๊ทธ์ธ ์„ฑ๊ณต + switch authorization.credential { + case let appleIDCredential as ASAuthorizationAppleIDCredential: + // You can create an account in your system. + let userIdentifier = appleIDCredential.user + let fullName = appleIDCredential.fullName + let email = appleIDCredential.email + + UserDefaults.standard.set(userIdentifier, forKey: "userIdentifier") + if let authorizationCode = appleIDCredential.authorizationCode, + let identityToken = appleIDCredential.identityToken, + let authCodeString = String(data: authorizationCode, encoding: .utf8), + let identifyTokenString = String(data: identityToken, encoding: .utf8) { + print("authorizationCode: \(authorizationCode)") + print("identityToken: \(identityToken)") + print("authCodeString: \(authCodeString)") + print("identifyTokenString: \(identifyTokenString)") + print("๐Ÿšจ", appleIDCredential) + if let bundleID = Bundle.main.bundleIdentifier { + UserDefaults.standard.removePersistentDomain(forName: bundleID) + } + // saveToUserDefaults("authorizationCode",keyValue: authorizationCode) + // saveToUserDefaults("identityToken",keyValue: identityToken) + // saveToUserDefaults(authCodeString,keyValue:"authCodeString") + // saveToUserDefaults(identifyTokenString,keyValue:"identifyTokenString") + // saveToUserDefaults("cool",keyValue:"userIdentifier") + + } + + print("useridentifier: \(userIdentifier)") + + + + //Move to MainPage + //let validVC = SignValidViewController() + //validVC.modalPresentationStyle = .fullScreen + //present(validVC, animated: true, completion: nil) + + case let passwordCredential as ASPasswordCredential: + // Sign in using an existing iCloud Keychain credential. + let username = passwordCredential.user + let password = passwordCredential.password + + print("username: \(username)") + print("password: \(password)") + + default: + break + } + } + + func saveToUserDefaults(_ content: String, keyValue: String) { + // Save the userId to UserDefaults + UserDefaults.standard.set(content, forKey: keyValue) + } + + + func authorizationController(controller: ASAuthorizationController, didCompleteWithError error: Error) { + // ๋กœ๊ทธ์ธ ์‹คํŒจ(์œ ์ €์˜ ์ทจ์†Œ๋„ ํฌํ•จ) + print("login failed - \(error.localizedDescription)") + } +} From e64b7f907865538f5571639364771ca6eb84033d Mon Sep 17 00:00:00 2001 From: kim-seonwoo Date: Thu, 11 Jan 2024 17:43:11 +0900 Subject: [PATCH 03/26] =?UTF-8?q?[Fix/#46]=20SignModel=20-=20=EC=A3=BC?= =?UTF-8?q?=EC=84=9D=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Onboarding/Models/SignInModel.swift | 46 +++++++++---------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/HMH_iOS/HMH_iOS/Presentation/Onboarding/Models/SignInModel.swift b/HMH_iOS/HMH_iOS/Presentation/Onboarding/Models/SignInModel.swift index 05871b7..d5d1095 100644 --- a/HMH_iOS/HMH_iOS/Presentation/Onboarding/Models/SignInModel.swift +++ b/HMH_iOS/HMH_iOS/Presentation/Onboarding/Models/SignInModel.swift @@ -5,26 +5,26 @@ // Created by Seonwoo Kim on 1/9/24. // -import Foundation - -struct SignInModel { - let socialPlatform: String - let onboarding: Onboarding - let challenge: Challenge -} - -struct Onboarding { - let averageUseTime: String - let problem: [String] -} - -struct Challenge { - let period: Int - let goalTime: Int - let apps: [Apps] -} - -struct Apps { - let appCode: String - let goalTime: Int -} +//import Foundation +// +//struct SignInModel { +// let socialPlatform: String +// let onboarding: Onboarding +// let challenge: Challenge +//} +// +//struct Onboarding { +// let averageUseTime: String +// let problem: [String] +//} +// +//struct Challenge { +// let period: Int +// let goalTime: Int +// let apps: [Apps] +//} +// +//struct Apps { +// let appCode: String +// let goalTime: Int +//} From d8e17277a164d332a4c32266eba16a4f3e7fdfa2 Mon Sep 17 00:00:00 2001 From: Zoe Date: Fri, 12 Jan 2024 03:11:45 +0900 Subject: [PATCH 04/26] =?UTF-8?q?[Chore/#51]=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20=EC=BD=94=EB=93=9C=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Splash/ViewControllers/SplashViewController.swift | 8 -------- 1 file changed, 8 deletions(-) diff --git a/HMH_iOS/HMH_iOS/Presentation/Splash/ViewControllers/SplashViewController.swift b/HMH_iOS/HMH_iOS/Presentation/Splash/ViewControllers/SplashViewController.swift index 6b15c60..75ac75c 100644 --- a/HMH_iOS/HMH_iOS/Presentation/Splash/ViewControllers/SplashViewController.swift +++ b/HMH_iOS/HMH_iOS/Presentation/Splash/ViewControllers/SplashViewController.swift @@ -10,17 +10,9 @@ import Moya final class SplashViewController: UIViewController { - let apiManager = APIManager() override func viewDidLoad() { super.viewDidLoad() view.backgroundColor = .systemYellow - let request = WeatherRequestDTO(q: "Seoul") - apiManager.weather(request: request) { data in - print(data) - } failure: { error in - print(error) - } - } } From b722fd50432a6226db525eedb9c6898deb9309b6 Mon Sep 17 00:00:00 2001 From: Zoe Date: Fri, 12 Jan 2024 03:55:41 +0900 Subject: [PATCH 05/26] [Chore/#51] Code Convention --- HMH_iOS/HMH_iOS/Network/Base/BaseModel.swift | 1 - HMH_iOS/HMH_iOS/Network/Base/BaseTargetType.swift | 2 -- HMH_iOS/HMH_iOS/Network/Router/ChallengeRouter.swift | 1 - 3 files changed, 4 deletions(-) diff --git a/HMH_iOS/HMH_iOS/Network/Base/BaseModel.swift b/HMH_iOS/HMH_iOS/Network/Base/BaseModel.swift index 2fd4689..399fd3d 100644 --- a/HMH_iOS/HMH_iOS/Network/Base/BaseModel.swift +++ b/HMH_iOS/HMH_iOS/Network/Base/BaseModel.swift @@ -12,4 +12,3 @@ struct BaseResponse: Decodable { var message: String? var data: T? } - diff --git a/HMH_iOS/HMH_iOS/Network/Base/BaseTargetType.swift b/HMH_iOS/HMH_iOS/Network/Base/BaseTargetType.swift index 69b3c50..7cedf55 100644 --- a/HMH_iOS/HMH_iOS/Network/Base/BaseTargetType.swift +++ b/HMH_iOS/HMH_iOS/Network/Base/BaseTargetType.swift @@ -8,8 +8,6 @@ import Foundation import Moya - - protocol BaseTargetType: TargetType {} typealias Parameters = [String: String] diff --git a/HMH_iOS/HMH_iOS/Network/Router/ChallengeRouter.swift b/HMH_iOS/HMH_iOS/Network/Router/ChallengeRouter.swift index 5487f2a..581e550 100644 --- a/HMH_iOS/HMH_iOS/Network/Router/ChallengeRouter.swift +++ b/HMH_iOS/HMH_iOS/Network/Router/ChallengeRouter.swift @@ -35,4 +35,3 @@ extension ChallengeRouter: BaseTargetType { } } } - From 3bc57c92dec25b1db4f76797b5dda7d420b2c0e6 Mon Sep 17 00:00:00 2001 From: kim-seonwoo Date: Fri, 12 Jan 2024 14:24:17 +0900 Subject: [PATCH 06/26] =?UTF-8?q?[Feat/#46]=20LoginViewController=20-=20?= =?UTF-8?q?=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=EC=84=B1=EA=B3=B5=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ViewControllers/LoginViewController.swift | 51 ++++++++++--------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/HMH_iOS/HMH_iOS/Presentation/Login/ViewControllers/LoginViewController.swift b/HMH_iOS/HMH_iOS/Presentation/Login/ViewControllers/LoginViewController.swift index 42a26ce..a1483b2 100644 --- a/HMH_iOS/HMH_iOS/Presentation/Login/ViewControllers/LoginViewController.swift +++ b/HMH_iOS/HMH_iOS/Presentation/Login/ViewControllers/LoginViewController.swift @@ -12,30 +12,9 @@ import Then import AuthenticationServices final class LoginViewController: UIViewController { - let authorizationButton = ASAuthorizationAppleIDButton(authorizationButtonType: .signIn, authorizationButtonStyle: .white) - func setAppleLoginButton() { - authorizationButton.addTarget(self, action: #selector(handleAuthorizationAppleIDButtonPress), for: .touchUpInside) - self.view.addSubview(authorizationButton) - authorizationButton.translatesAutoresizingMaskIntoConstraints = false - } - @objc - func handleAuthorizationAppleIDButtonPress() { - let appleIDProvider = ASAuthorizationAppleIDProvider() - let request = appleIDProvider.createRequest() - request.requestedScopes = [.fullName, .email] - print(request, "๐Ÿ‘") - let authorizationController = ASAuthorizationController(authorizationRequests: [request]) - authorizationController.delegate = self - authorizationController.presentationContextProvider = self - authorizationController.performRequests() - } - - @objc func appleButtonTaped() { - print("tap") - } - - let swipeView = OnboardingSwipeView() + private let swipeView = OnboardingSwipeView() + let authorizationButton = ASAuthorizationAppleIDButton(authorizationButtonType: .signIn, authorizationButtonStyle: .white) override func viewDidLoad() { super.viewDidLoad() @@ -68,6 +47,32 @@ final class LoginViewController: UIViewController { } } +extension LoginViewController { + + func setAppleLoginButton() { + authorizationButton.addTarget(self, action: #selector(handleAuthorizationAppleIDButtonPress), for: .touchUpInside) + self.view.addSubview(authorizationButton) + authorizationButton.translatesAutoresizingMaskIntoConstraints = false + } + + @objc + func handleAuthorizationAppleIDButtonPress() { + let appleIDProvider = ASAuthorizationAppleIDProvider() + let request = appleIDProvider.createRequest() + request.requestedScopes = [.email] + print(request, "๐Ÿ‘") + let authorizationController = ASAuthorizationController(authorizationRequests: [request]) + authorizationController.delegate = self + authorizationController.presentationContextProvider = self + authorizationController.performRequests() + } + + @objc func appleButtonTaped() { + print("tap") + } + +} + extension LoginViewController: ASAuthorizationControllerDelegate, ASAuthorizationControllerPresentationContextProviding{ func presentationAnchor(for controller: ASAuthorizationController) -> ASPresentationAnchor { From f3948fd40f3e036ad53dd37a3846f291bc37fd62 Mon Sep 17 00:00:00 2001 From: Zoe Date: Fri, 12 Jan 2024 14:51:52 +0900 Subject: [PATCH 07/26] =?UTF-8?q?[Set/#53]=20=EB=84=A4=ED=8A=B8=EC=9B=8C?= =?UTF-8?q?=ED=81=AC=20=EC=84=B8=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HMH_iOS/HMH_iOS/Info.plist | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/HMH_iOS/HMH_iOS/Info.plist b/HMH_iOS/HMH_iOS/Info.plist index 1c20cb8..9fcb576 100644 --- a/HMH_iOS/HMH_iOS/Info.plist +++ b/HMH_iOS/HMH_iOS/Info.plist @@ -33,5 +33,10 @@ + NSAppTransportSecurity + + NSAllowsArbitraryLoads + + From 10f9fb8a7c238e96c700cafdaf5c4a663e0e1127 Mon Sep 17 00:00:00 2001 From: Zoe Date: Fri, 12 Jan 2024 15:46:30 +0900 Subject: [PATCH 08/26] =?UTF-8?q?[Fix/#53]=20=EB=84=A4=ED=8A=B8=EC=9B=8C?= =?UTF-8?q?=ED=81=AC=20=ED=86=B5=EC=8B=A0=20=EC=98=A4=EB=A5=98=20=ED=95=B4?= =?UTF-8?q?=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HMH_iOS/HMH_iOS/Network/Base/BaseTargetType.swift | 4 ---- HMH_iOS/HMH_iOS/Network/Service/Providers.swift | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/HMH_iOS/HMH_iOS/Network/Base/BaseTargetType.swift b/HMH_iOS/HMH_iOS/Network/Base/BaseTargetType.swift index 7cedf55..b2c2d33 100644 --- a/HMH_iOS/HMH_iOS/Network/Base/BaseTargetType.swift +++ b/HMH_iOS/HMH_iOS/Network/Base/BaseTargetType.swift @@ -29,8 +29,4 @@ extension BaseTargetType { var sampleData: Data { return Data() } - - var validationType: ValidationType { - return .successCodes - } } diff --git a/HMH_iOS/HMH_iOS/Network/Service/Providers.swift b/HMH_iOS/HMH_iOS/Network/Service/Providers.swift index 5c7447b..0de78f3 100644 --- a/HMH_iOS/HMH_iOS/Network/Service/Providers.swift +++ b/HMH_iOS/HMH_iOS/Network/Service/Providers.swift @@ -9,7 +9,7 @@ import Foundation import Moya struct Providers { - static let departureSearchingProvider = MoyaProvider(withAuth: false) + static let challengeProvider = NetworkProvider(withAuth: false) } extension MoyaProvider { From 7b114d9116e48a41c0771608fd2dff4d9e3a9488 Mon Sep 17 00:00:00 2001 From: Zoe Date: Fri, 12 Jan 2024 19:21:30 +0900 Subject: [PATCH 09/26] =?UTF-8?q?[Set/#53]=20=20=EB=84=A4=ED=8A=B8?= =?UTF-8?q?=EC=9B=8C=ED=81=AC=20=EC=84=B8=ED=8C=85=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../HMH_iOS/Network/Base/BaseTargetType.swift | 1 + .../Network/Foundation/APIConstants.swift | 6 +-- .../Network/Foundation/NetworkHelper.swift | 1 + .../Network/Foundation/NetworkRequest.swift | 44 +++++++++---------- .../Network/Router/ChallengeRouter.swift | 13 ++++-- 5 files changed, 36 insertions(+), 29 deletions(-) diff --git a/HMH_iOS/HMH_iOS/Network/Base/BaseTargetType.swift b/HMH_iOS/HMH_iOS/Network/Base/BaseTargetType.swift index b2c2d33..eb0b5cc 100644 --- a/HMH_iOS/HMH_iOS/Network/Base/BaseTargetType.swift +++ b/HMH_iOS/HMH_iOS/Network/Base/BaseTargetType.swift @@ -29,4 +29,5 @@ extension BaseTargetType { var sampleData: Data { return Data() } + } diff --git a/HMH_iOS/HMH_iOS/Network/Foundation/APIConstants.swift b/HMH_iOS/HMH_iOS/Network/Foundation/APIConstants.swift index 7b66696..6545e11 100644 --- a/HMH_iOS/HMH_iOS/Network/Foundation/APIConstants.swift +++ b/HMH_iOS/HMH_iOS/Network/Foundation/APIConstants.swift @@ -12,15 +12,15 @@ struct APIConstants{ static let contentType = "Content-Type" static let applicationJSON = "application/json" static let auth = "Authorization" - static let accessToken = "" // TO-DO: AccessToken - static let appleAccessToken = "" + static let accessToken = "Bearer " // TO-DO: AccessToken + static let appleAccessToken = "" static let OS = "OS" static let iOS = "iOS" } extension APIConstants{ static let hasSocialTokenHeader = [contentType: applicationJSON, - auth : accessToken] + auth : appleAccessToken] static let hasTokenHeader = [contentType: applicationJSON, OS: iOS, auth : accessToken] diff --git a/HMH_iOS/HMH_iOS/Network/Foundation/NetworkHelper.swift b/HMH_iOS/HMH_iOS/Network/Foundation/NetworkHelper.swift index 010014e..30c119e 100644 --- a/HMH_iOS/HMH_iOS/Network/Foundation/NetworkHelper.swift +++ b/HMH_iOS/HMH_iOS/Network/Foundation/NetworkHelper.swift @@ -35,4 +35,5 @@ struct NetworkHelper { default: return .networkFail } } + } diff --git a/HMH_iOS/HMH_iOS/Network/Foundation/NetworkRequest.swift b/HMH_iOS/HMH_iOS/Network/Foundation/NetworkRequest.swift index 18325c4..db9907b 100644 --- a/HMH_iOS/HMH_iOS/Network/Foundation/NetworkRequest.swift +++ b/HMH_iOS/HMH_iOS/Network/Foundation/NetworkRequest.swift @@ -8,29 +8,27 @@ import Foundation import Moya -struct NetworkRequest { - let url: String - let httpMethod: Moya.Method - let body: Data? // optional - let headers: [String: String]? // optional - - init(url: String, - httpMethod: Moya.Method, - requestBody: Data? = nil, - headers: [String: String]? = nil - ) { - self.url = url - self.httpMethod = httpMethod - self.body = requestBody - self.headers = headers +struct ResponseData { + struct CommonResponse: Codable { + let result: Model } - - func createURLRequest(with url: URL) -> URLRequest { - var urlRequest = URLRequest(url: url) - urlRequest.httpMethod = httpMethod.rawValue - urlRequest.httpBody = body - urlRequest.allHTTPHeaderFields = headers ?? [:] - return urlRequest + + static func processResponse(_ result: Result) -> Result { + switch result { + case .success(let response): + do { + // status code๊ฐ€ 200...299์ธ ๊ฒฝ์šฐ๋งŒ success๋กœ ์ฒดํฌ (์•„๋‹ˆ๋ฉด ์˜ˆ์™ธ๋ฐœ์ƒ) + _ = try response.filterSuccessfulStatusCodes() + + let commonResponse = try JSONDecoder().decode(CommonResponse.self, from: response.data) + return .success(commonResponse.result) + } catch { + return .failure(error) + } + + case .failure(let error): + return .failure(error) + } } + } - diff --git a/HMH_iOS/HMH_iOS/Network/Router/ChallengeRouter.swift b/HMH_iOS/HMH_iOS/Network/Router/ChallengeRouter.swift index 581e550..91bc27d 100644 --- a/HMH_iOS/HMH_iOS/Network/Router/ChallengeRouter.swift +++ b/HMH_iOS/HMH_iOS/Network/Router/ChallengeRouter.swift @@ -10,10 +10,17 @@ import Foundation import Moya enum ChallengeRouter { - case createChallenge + case createChallenge(data: CreateChallengeRequestDTO) } extension ChallengeRouter: BaseTargetType { + private var headers: Parameters { + switch self { + case .createChallenge: + return APIConstants.hasTokenHeader + } + } + var path: String { switch self { case .createChallenge: @@ -30,8 +37,8 @@ extension ChallengeRouter: BaseTargetType { var task: Moya.Task { switch self { - case .createChallenge: - return .requestPlain // ์ถ”ํ›„ ๋ณ€๊ฒฝ ์™„๋ฃŒ + case .createChallenge(let data): + return .requestJSONEncodable(data) } } } From 907a38275fee5528ea2d451819589da5e2f69404 Mon Sep 17 00:00:00 2001 From: Zoe Date: Fri, 12 Jan 2024 19:22:01 +0900 Subject: [PATCH 10/26] =?UTF-8?q?[Network/#53]=20DTO=20=EC=98=88=EC=8B=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CreateChallengeRequestDTO.swift | 10 ++++++++-- .../CreateChallengeResponseDTO.swift | 17 +++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 HMH_iOS/HMH_iOS/Network/DTO/ChallengeModel/CreateChallengeResponseDTO.swift diff --git a/HMH_iOS/HMH_iOS/Network/DTO/ChallengeModel/CreateChallengeRequestDTO.swift b/HMH_iOS/HMH_iOS/Network/DTO/ChallengeModel/CreateChallengeRequestDTO.swift index 498edae..5086216 100644 --- a/HMH_iOS/HMH_iOS/Network/DTO/ChallengeModel/CreateChallengeRequestDTO.swift +++ b/HMH_iOS/HMH_iOS/Network/DTO/ChallengeModel/CreateChallengeRequestDTO.swift @@ -7,6 +7,12 @@ import Foundation -class CreateChallengeRequestDTO: Request { - +struct CreateChallengeRequestDTO: Codable { + let period, goalTime: Int + let apps: [App] +} + +struct App: Codable { + let appCode: String + let appGoalTime: Int } diff --git a/HMH_iOS/HMH_iOS/Network/DTO/ChallengeModel/CreateChallengeResponseDTO.swift b/HMH_iOS/HMH_iOS/Network/DTO/ChallengeModel/CreateChallengeResponseDTO.swift new file mode 100644 index 0000000..e510752 --- /dev/null +++ b/HMH_iOS/HMH_iOS/Network/DTO/ChallengeModel/CreateChallengeResponseDTO.swift @@ -0,0 +1,17 @@ +// +// CreateChallengeResponseDTO.swift +// HMH_iOS +// +// Created by ์ง€ํฌ์˜ MAC on 1/12/24. +// + +import Foundation + +struct CreateChallengeResponseDTO: Codable { + let challengeID: Int + + enum CodingKeys: String, CodingKey { + case challengeID = "challengeId" + + } +} From 438ba60a56cf9ee50ee4f063b55134ca070a844c Mon Sep 17 00:00:00 2001 From: Zoe Date: Fri, 12 Jan 2024 19:22:45 +0900 Subject: [PATCH 11/26] =?UTF-8?q?[Network/#53]=20Provider=20=EC=98=88?= =?UTF-8?q?=EC=8B=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HMH_iOS/HMH_iOS/Network/Service/Providers.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/HMH_iOS/HMH_iOS/Network/Service/Providers.swift b/HMH_iOS/HMH_iOS/Network/Service/Providers.swift index 0de78f3..d0cccc9 100644 --- a/HMH_iOS/HMH_iOS/Network/Service/Providers.swift +++ b/HMH_iOS/HMH_iOS/Network/Service/Providers.swift @@ -12,7 +12,7 @@ struct Providers { static let challengeProvider = NetworkProvider(withAuth: false) } -extension MoyaProvider { +extension NetworkProvider { convenience init(withAuth: Bool) { if withAuth { self.init(session: Session(interceptor: AuthInterceptor.shared), From 587ac58050c889c58309df3b0d558a36943e157c Mon Sep 17 00:00:00 2001 From: Zoe Date: Fri, 12 Jan 2024 19:23:26 +0900 Subject: [PATCH 12/26] =?UTF-8?q?[Feat/#53]=20Interceptor=20=EC=84=B8?= =?UTF-8?q?=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HMH_iOS/HMH_iOS/Network/Base/AuthInterceptor.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/HMH_iOS/HMH_iOS/Network/Base/AuthInterceptor.swift b/HMH_iOS/HMH_iOS/Network/Base/AuthInterceptor.swift index 089f3e2..bfb3da4 100644 --- a/HMH_iOS/HMH_iOS/Network/Base/AuthInterceptor.swift +++ b/HMH_iOS/HMH_iOS/Network/Base/AuthInterceptor.swift @@ -21,5 +21,6 @@ final class AuthInterceptor: RequestInterceptor { } func retry(_ request: Request, for session: Session, dueTo error: Error, completion: @escaping (RetryResult) -> Void) { + print("retry") } } From 8f69dcfc0634240c869c97a0c9d0e69b92c3a64d Mon Sep 17 00:00:00 2001 From: Zoe Date: Fri, 12 Jan 2024 19:23:47 +0900 Subject: [PATCH 13/26] =?UTF-8?q?[Chore/#53]=20=ED=94=84=EB=A1=9C=EC=A0=9D?= =?UTF-8?q?=ED=8A=B8=ED=8C=8C=EC=9D=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HMH_iOS/HMH_iOS.xcodeproj/project.pbxproj | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/HMH_iOS/HMH_iOS.xcodeproj/project.pbxproj b/HMH_iOS/HMH_iOS.xcodeproj/project.pbxproj index 285645b..fad39ee 100644 --- a/HMH_iOS/HMH_iOS.xcodeproj/project.pbxproj +++ b/HMH_iOS/HMH_iOS.xcodeproj/project.pbxproj @@ -56,6 +56,7 @@ 174AF4982B447CF100450D07 /* ChanllengeModels.swift in Sources */ = {isa = PBXBuildFile; fileRef = 174AF4972B447CF100450D07 /* ChanllengeModels.swift */; }; 174AF49A2B447CFB00450D07 /* ChanllengeViews.swift in Sources */ = {isa = PBXBuildFile; fileRef = 174AF4992B447CFB00450D07 /* ChanllengeViews.swift */; }; 174AF49C2B447D0700450D07 /* ChallengeViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 174AF49B2B447D0700450D07 /* ChallengeViewController.swift */; }; + 363863BA2B50782E000FE5E7 /* CreateChallengeResponseDTO.swift in Sources */ = {isa = PBXBuildFile; fileRef = 363863B92B50782E000FE5E7 /* CreateChallengeResponseDTO.swift */; }; 364923652B4F4FB800BF7ACA /* Config.swift in Sources */ = {isa = PBXBuildFile; fileRef = 364923642B4F4FB800BF7ACA /* Config.swift */; }; 364923682B4F513600BF7ACA /* BaseTargetType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 364923672B4F513600BF7ACA /* BaseTargetType.swift */; }; 3649236A2B4F514A00BF7ACA /* Moya in Frameworks */ = {isa = PBXBuildFile; productRef = 364923692B4F514A00BF7ACA /* Moya */; }; @@ -219,6 +220,7 @@ 174AF4972B447CF100450D07 /* ChanllengeModels.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChanllengeModels.swift; sourceTree = ""; }; 174AF4992B447CFB00450D07 /* ChanllengeViews.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChanllengeViews.swift; sourceTree = ""; }; 174AF49B2B447D0700450D07 /* ChallengeViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChallengeViewController.swift; sourceTree = ""; }; + 363863B92B50782E000FE5E7 /* CreateChallengeResponseDTO.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreateChallengeResponseDTO.swift; sourceTree = ""; }; 364923612B4F4E7D00BF7ACA /* Config.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Config.xcconfig; sourceTree = ""; }; 364923642B4F4FB800BF7ACA /* Config.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Config.swift; sourceTree = ""; }; 364923672B4F513600BF7ACA /* BaseTargetType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BaseTargetType.swift; sourceTree = ""; }; @@ -812,6 +814,7 @@ isa = PBXGroup; children = ( 3649239F2B505F2000BF7ACA /* CreateChallengeRequestDTO.swift */, + 363863B92B50782E000FE5E7 /* CreateChallengeResponseDTO.swift */, ); path = ChallengeModel; sourceTree = ""; @@ -1141,6 +1144,7 @@ 3666C89B2B48516500564874 /* ChallengeView.swift in Sources */, 364923682B4F513600BF7ACA /* BaseTargetType.swift in Sources */, 3666C88D2B471B1D00564874 /* UIImage+.swift in Sources */, + 363863BA2B50782E000FE5E7 /* CreateChallengeResponseDTO.swift in Sources */, 3666C87C2B45F50F00564874 /* BlockingApplicationModel.swift in Sources */, 0B0035402B43D64D00DA140C /* HMHNavigationBar.swift in Sources */, 0BA193B22B4CE908007E3F9C /* SurveyView.swift in Sources */, From 5f52d3e5f8dac615cc38577309188b245682f74d Mon Sep 17 00:00:00 2001 From: Zoe Date: Fri, 12 Jan 2024 22:02:50 +0900 Subject: [PATCH 14/26] =?UTF-8?q?[Chore/#53]=20=EB=B6=88=ED=95=84=EC=9A=94?= =?UTF-8?q?=ED=95=9C=20=ED=8C=8C=EC=9D=BC=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Network/Service/WeatherTarget.swift | 79 ------------------- 1 file changed, 79 deletions(-) delete mode 100644 HMH_iOS/HMH_iOS/Network/Service/WeatherTarget.swift diff --git a/HMH_iOS/HMH_iOS/Network/Service/WeatherTarget.swift b/HMH_iOS/HMH_iOS/Network/Service/WeatherTarget.swift deleted file mode 100644 index cd7aba1..0000000 --- a/HMH_iOS/HMH_iOS/Network/Service/WeatherTarget.swift +++ /dev/null @@ -1,79 +0,0 @@ -// -// WheatherProvider.swift -// HMH_iOS -// -// Created by ์ง€ํฌ์˜ MAC on 1/11/24. -// - -import Foundation -import Moya - -enum WeatherTarget { - case getWeather(WeatherRequestDTO) -} - -extension WeatherTarget: BaseTargetType { - var method: Moya.Method { - switch self { - case .getWeather: - return .get - } - } - - var path: String { - switch self { - case .getWeather: return "weather" - } - } - - var task: Task { - switch self { - case .getWeather(WeatherRequestDTO(q: "")) - return .requestPlain - } - } -} - - - - -struct APIManager { - - private let provider = MoyaProvider() - - let customEndpointClosure = { (target : WeatherTarget) -> Endpoint in - - return Endpoint(url: URL(target: target).absoluteString, sampleResponseClosure: {.networkResponse(400, target.sampleData)}, method: target.method, task: target.task, httpHeaderFields: target.headers) - - } - let weatherRequest = WeatherRequestDTO(q: "Seoul") - private var testingProvider : MoyaProvider? - - init(){ - - testingProvider = .init(endpointClosure: customEndpointClosure,stubClosure: MoyaProvider.immediatelyStub) - - } - - func weather(request: WeatherRequestDTO, completion : @escaping ([WeatherDTO]) -> () , failure : @escaping (String) -> ()){ - - provider.request(.getWeather(request), completion: { result in - switch result { - case let .success(response) : - do { - let weathermodel = try JSONDecoder().decode([WeatherDTO].self, from: response.data) - - completion(weathermodel) - } - catch let error{ - failure(error.localizedDescription) - } - - case let .failure(error): - failure(error.localizedDescription) - } - - }) - } - -} From 6e6aec546cd84cadc84c7f3e8be671665f28a6ee Mon Sep 17 00:00:00 2001 From: kim-seonwoo Date: Fri, 12 Jan 2024 22:34:20 +0900 Subject: [PATCH 15/26] =?UTF-8?q?[Add/#46]=20UserManager=20=ED=8C=8C?= =?UTF-8?q?=EC=9D=BC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HMH_iOS/HMH_iOS.xcodeproj/project.pbxproj | 16 ++++ .../SupportingFiles/User/UserManager.swift | 90 +++++++++++++++++++ 2 files changed, 106 insertions(+) create mode 100644 HMH_iOS/HMH_iOS/Global/SupportingFiles/User/UserManager.swift diff --git a/HMH_iOS/HMH_iOS.xcodeproj/project.pbxproj b/HMH_iOS/HMH_iOS.xcodeproj/project.pbxproj index 6fc1f6e..918da6e 100644 --- a/HMH_iOS/HMH_iOS.xcodeproj/project.pbxproj +++ b/HMH_iOS/HMH_iOS.xcodeproj/project.pbxproj @@ -12,6 +12,8 @@ 0B000CED2B4D9DA800AEC582 /* ApprovePermisionController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B000CEC2B4D9DA800AEC582 /* ApprovePermisionController.swift */; }; 0B000CF12B4DA30F00AEC582 /* AppSelectViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B000CF02B4DA30F00AEC582 /* AppSelectViewController.swift */; }; 0B0035402B43D64D00DA140C /* HMHNavigationBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B00353F2B43D64D00DA140C /* HMHNavigationBar.swift */; }; + 0B17D3EB2B5104E000CFA3B7 /* UserManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B17D3EA2B5104E000CFA3B7 /* UserManager.swift */; }; + 0B17D3ED2B5108D200CFA3B7 /* UserDefaultWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B17D3EC2B5108D200CFA3B7 /* UserDefaultWrapper.swift */; }; 0B2C2D3B2B443BE90023CCFA /* Image.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B2C2D3A2B443BE90023CCFA /* Image.swift */; }; 0B2C2D412B4572240023CCFA /* HMHSelectButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B2C2D402B4572240023CCFA /* HMHSelectButton.swift */; }; 0B50F9CB2B369813000C5046 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B50F9CA2B369813000C5046 /* AppDelegate.swift */; }; @@ -163,6 +165,8 @@ 0B000CEC2B4D9DA800AEC582 /* ApprovePermisionController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ApprovePermisionController.swift; sourceTree = ""; }; 0B000CF02B4DA30F00AEC582 /* AppSelectViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppSelectViewController.swift; sourceTree = ""; }; 0B00353F2B43D64D00DA140C /* HMHNavigationBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HMHNavigationBar.swift; sourceTree = ""; }; + 0B17D3EA2B5104E000CFA3B7 /* UserManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserManager.swift; sourceTree = ""; }; + 0B17D3EC2B5108D200CFA3B7 /* UserDefaultWrapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserDefaultWrapper.swift; sourceTree = ""; }; 0B2C2D3A2B443BE90023CCFA /* Image.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Image.swift; sourceTree = ""; }; 0B2C2D402B4572240023CCFA /* HMHSelectButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HMHSelectButton.swift; sourceTree = ""; }; 0B50F9C72B369813000C5046 /* HMH_iOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = HMH_iOS.app; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -310,6 +314,15 @@ path = ViewControllers; sourceTree = ""; }; + 0B17D3E92B5104B900CFA3B7 /* User */ = { + isa = PBXGroup; + children = ( + 0B17D3EA2B5104E000CFA3B7 /* UserManager.swift */, + 0B17D3EC2B5108D200CFA3B7 /* UserDefaultWrapper.swift */, + ); + path = User; + sourceTree = ""; + }; 0B2C2D3C2B4559AE0023CCFA /* Onboarding */ = { isa = PBXGroup; children = ( @@ -458,6 +471,7 @@ 0B8A89982B369CF800688BA6 /* SupportingFiles */ = { isa = PBXGroup; children = ( + 0B17D3E92B5104B900CFA3B7 /* User */, 3666C8782B45F4D900564874 /* AppBlock */, 0B8A89992B369D0B00688BA6 /* Base */, ); @@ -1012,6 +1026,7 @@ 0B8A89AF2B369E4300688BA6 /* HomeModel.swift in Sources */, 3666C89F2B485C8F00564874 /* DateCollectionViewCell.swift in Sources */, 3666C87A2B45F4F900564874 /* SelectedBlocker.swift in Sources */, + 0B17D3ED2B5108D200CFA3B7 /* UserDefaultWrapper.swift in Sources */, 0BC0EBD42B494459003EF5D4 /* OnboardingSwipeView.swift in Sources */, 17314F9B2B4C485B0089A551 /* UserPointHeaderView.swift in Sources */, 36A3D9C02B409CBD007EA272 /* Font.swift in Sources */, @@ -1022,6 +1037,7 @@ 174AF4942B447B5500450D07 /* MyPageViewController.swift in Sources */, 0BA193B42B4D089C007E3F9C /* TimeSurveyViewController.swift in Sources */, 36A3D9B82B3EBC3B007EA272 /* UILabel+.swift in Sources */, + 0B17D3EB2B5104E000CFA3B7 /* UserManager.swift in Sources */, 0B50F9CB2B369813000C5046 /* AppDelegate.swift in Sources */, 0B7817522B4BE0280078E925 /* ProgressBarManager.swift in Sources */, 0B8A89C42B369FA000688BA6 /* F.swift in Sources */, diff --git a/HMH_iOS/HMH_iOS/Global/SupportingFiles/User/UserManager.swift b/HMH_iOS/HMH_iOS/Global/SupportingFiles/User/UserManager.swift new file mode 100644 index 0000000..7b9f626 --- /dev/null +++ b/HMH_iOS/HMH_iOS/Global/SupportingFiles/User/UserManager.swift @@ -0,0 +1,90 @@ +// +// UserManager.swift +// HMH_iOS +// +// Created by Seonwoo Kim on 1/12/24. +// + +import Foundation + +final class UserManager { + static let shared = UserManager() + + @UserDefaultWrapper(key: "accessToken") private(set) var accessToken + @UserDefaultWrapper(key: "refreshToken") private(set) var refreshToken + @UserDefaultWrapper(key: "AppleToken") private(set) var appleToken + @UserDefaultWrapper(key: "userIdentifier") private(set) var appleUserIdentifier + @UserDefaultWrapper(key: "familyName") private(set) var familyName + @UserDefaultWrapper(key: "givenName") private(set) var givenName + @UserDefaultWrapper(key: "fullName") private(set) var fullName + @UserDefaultWrapper(key: "userId") private(set) var userId + + var hasAccessToken: Bool { return self.accessToken != nil } + var getAccessToken: String { return self.accessToken ?? "" } + var getRefreshToken: String { return self.refreshToken ?? "" } + var getAppleToken: String { return self.appleToken ?? "" } + var getUserIdentifier: String { return self.appleUserIdentifier ?? "" } + var getUserName: String { return self.familyName ?? "" } + var getGivenName: String { return self.givenName ?? "" } + var getFullName: String { return self.fullName ?? "" } + var getUserId: Int { return self.userId ?? 0} + + var haveFullName: Bool { + if fullName == "" { + return false + } else if fullName == nil { + return false + } else { + return true + } + } + + private init() {} +} + +extension UserManager { + func updateToken(_ accessToken: String, _ refreshToken: String) { + self.accessToken = accessToken + self.refreshToken = refreshToken + } + + func updateAppleToken(_ appleToken: String) { + self.appleToken = appleToken + } + + func updateUserIdentifier(_ appleUserIdentifier: String) { + self.appleUserIdentifier = appleUserIdentifier + } + + func updateUserName(_ givenName: String, _ familyName: String) { + self.givenName = givenName + self.familyName = familyName + self.fullName = familyName + givenName + } + + func updateUserId(_ userId: Int) { + self.userId = userId + } + + func setUserIdForApple(userId: String) { + self.appleUserIdentifier = appleUserIdentifier + } + + func clearAll() { + self.accessToken = nil + self.refreshToken = nil + self.appleToken = nil + self.appleUserIdentifier = nil + self.familyName = nil + self.givenName = nil + self.fullName = nil + self.userId = nil + } + + func clearData() { + self.accessToken = nil + self.refreshToken = nil + self.appleToken = nil + self.appleUserIdentifier = nil + } +} From 4c29f2b958b7d9de45ca4e8731cd43b62ffa9d50 Mon Sep 17 00:00:00 2001 From: kim-seonwoo Date: Fri, 12 Jan 2024 22:35:06 +0900 Subject: [PATCH 16/26] =?UTF-8?q?[Add/#46]=20UserDefaultWrapper=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../User/UserDefaultWrapper.swift | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 HMH_iOS/HMH_iOS/Global/SupportingFiles/User/UserDefaultWrapper.swift diff --git a/HMH_iOS/HMH_iOS/Global/SupportingFiles/User/UserDefaultWrapper.swift b/HMH_iOS/HMH_iOS/Global/SupportingFiles/User/UserDefaultWrapper.swift new file mode 100644 index 0000000..d4c8f86 --- /dev/null +++ b/HMH_iOS/HMH_iOS/Global/SupportingFiles/User/UserDefaultWrapper.swift @@ -0,0 +1,30 @@ +// +// UserDefaultWrapper.swift +// HMH_iOS +// +// Created by Seonwoo Kim on 1/12/24. +// + +import Foundation + +@propertyWrapper +struct UserDefaultWrapper { + + var wrappedValue: T? { + get { + return UserDefaults.standard.object(forKey: self.key) as? T + } + + set { + if newValue == nil { + UserDefaults.standard.removeObject(forKey: key) + } else { UserDefaults.standard.setValue(newValue, forKey: key) } + } + } + + private let key: String + + init(key: String) { + self.key = key + } +} From 9ae73f8688b9e07ecc88817e78d757887d2ddcfc Mon Sep 17 00:00:00 2001 From: kim-seonwoo Date: Fri, 12 Jan 2024 22:42:57 +0900 Subject: [PATCH 17/26] =?UTF-8?q?[Feat/#46]=20SceneDelegate=20-=20?= =?UTF-8?q?=EC=95=A0=ED=94=8C=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=EC=9C=A0?= =?UTF-8?q?=EC=A0=80=20=EC=83=81=ED=83=9C=20=EC=A1=B0=ED=9A=8C=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../HMH_iOS/Application/SceneDelegate.swift | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/HMH_iOS/HMH_iOS/Application/SceneDelegate.swift b/HMH_iOS/HMH_iOS/Application/SceneDelegate.swift index 629882e..9a3885a 100644 --- a/HMH_iOS/HMH_iOS/Application/SceneDelegate.swift +++ b/HMH_iOS/HMH_iOS/Application/SceneDelegate.swift @@ -6,11 +6,27 @@ // import UIKit +import AuthenticationServices class SceneDelegate: UIResponder, UIWindowSceneDelegate { var window: UIWindow? - + // + func sceneDidBecomeActive(_ scene: UIScene) { + let appleIDProvider = ASAuthorizationAppleIDProvider() + appleIDProvider.getCredentialState(forUserID: "000340.8d411a5d11d84e8da0c22ef43dce465a.1657" ?? "") { (credentialState, error) in + switch credentialState { + case .authorized: + print("authorized") + case .revoked: + print("revoked") + case .notFound: + print("notFound") + default: + break + } + } + } func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { guard let windowScene = (scene as? UIWindowScene) else { return } @@ -24,7 +40,15 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { DispatchQueue.main.asyncAfter(deadline: .now() + 2) { DispatchQueue.main.async{ - showLoginViewController() + if UserManager.shared.hasAccessToken { + //์• ํ”Œ ๋กœ๊ทธ์ธ ํ† ํฐ ๋ฆฌํ”„๋ ˆ์‰ฌ ๋กœ์ง. ์„ฑ๊ณตํ•œ๋‹ค๋ฉด ์—‘์„ธ์Šค์™€ ๋ฆฌํ”„๋ ˆ์‹œ ํ† ํฐ ์—…๋ฐ์ดํŠธ ๊ทธ๋Ÿฌ๋ฉด์„œ ์ด๋™ + // ํ† ํฐ ๋ฆฌํ”„๋ ˆ์‹œ๊ฐ€ ์‹คํŒจ ํ•œ๋‹ค. ๋กœ๊ทธ์ธ ์ปจํŠธ๋กค๋Ÿฌ๋กœ ๋ฐ”๋กœ ์ด๋™. +// UserManager.shared.updateToken(,) + + showTabBarViewController() + } else { + showLoginViewController() + } } } From 72c5cd933e1e19f9ef83988c3807660ff1915c55 Mon Sep 17 00:00:00 2001 From: kim-seonwoo Date: Fri, 12 Jan 2024 22:50:25 +0900 Subject: [PATCH 18/26] =?UTF-8?q?[Chore/#46]=20=EC=9E=90=EC=9E=98=ED=95=9C?= =?UTF-8?q?=20=EC=98=A4=EB=A5=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SupportingFiles/User/UserManager.swift | 8 +-- .../ViewControllers/LoginViewController.swift | 68 ++++++------------- 2 files changed, 26 insertions(+), 50 deletions(-) diff --git a/HMH_iOS/HMH_iOS/Global/SupportingFiles/User/UserManager.swift b/HMH_iOS/HMH_iOS/Global/SupportingFiles/User/UserManager.swift index 7b9f626..2db9ca3 100644 --- a/HMH_iOS/HMH_iOS/Global/SupportingFiles/User/UserManager.swift +++ b/HMH_iOS/HMH_iOS/Global/SupportingFiles/User/UserManager.swift @@ -47,7 +47,7 @@ extension UserManager { self.accessToken = accessToken self.refreshToken = refreshToken } - + func updateAppleToken(_ appleToken: String) { self.appleToken = appleToken } @@ -55,7 +55,7 @@ extension UserManager { func updateUserIdentifier(_ appleUserIdentifier: String) { self.appleUserIdentifier = appleUserIdentifier } - + func updateUserName(_ givenName: String, _ familyName: String) { self.givenName = givenName self.familyName = familyName @@ -65,11 +65,11 @@ extension UserManager { func updateUserId(_ userId: Int) { self.userId = userId } - + func setUserIdForApple(userId: String) { self.appleUserIdentifier = appleUserIdentifier } - + func clearAll() { self.accessToken = nil self.refreshToken = nil diff --git a/HMH_iOS/HMH_iOS/Presentation/Login/ViewControllers/LoginViewController.swift b/HMH_iOS/HMH_iOS/Presentation/Login/ViewControllers/LoginViewController.swift index a1483b2..3189ce7 100644 --- a/HMH_iOS/HMH_iOS/Presentation/Login/ViewControllers/LoginViewController.swift +++ b/HMH_iOS/HMH_iOS/Presentation/Login/ViewControllers/LoginViewController.swift @@ -59,21 +59,14 @@ extension LoginViewController { func handleAuthorizationAppleIDButtonPress() { let appleIDProvider = ASAuthorizationAppleIDProvider() let request = appleIDProvider.createRequest() - request.requestedScopes = [.email] - print(request, "๐Ÿ‘") + request.requestedScopes = [.fullName] let authorizationController = ASAuthorizationController(authorizationRequests: [request]) authorizationController.delegate = self authorizationController.presentationContextProvider = self authorizationController.performRequests() } - - @objc func appleButtonTaped() { - print("tap") - } - } - extension LoginViewController: ASAuthorizationControllerDelegate, ASAuthorizationControllerPresentationContextProviding{ func presentationAnchor(for controller: ASAuthorizationController) -> ASPresentationAnchor { return self.view.window! @@ -83,62 +76,45 @@ extension LoginViewController: ASAuthorizationControllerDelegate, ASAuthorizatio //๋กœ๊ทธ์ธ ์„ฑ๊ณต switch authorization.credential { case let appleIDCredential as ASAuthorizationAppleIDCredential: - // You can create an account in your system. let userIdentifier = appleIDCredential.user let fullName = appleIDCredential.fullName - let email = appleIDCredential.email - UserDefaults.standard.set(userIdentifier, forKey: "userIdentifier") if let authorizationCode = appleIDCredential.authorizationCode, let identityToken = appleIDCredential.identityToken, let authCodeString = String(data: authorizationCode, encoding: .utf8), let identifyTokenString = String(data: identityToken, encoding: .utf8) { - print("authorizationCode: \(authorizationCode)") - print("identityToken: \(identityToken)") - print("authCodeString: \(authCodeString)") - print("identifyTokenString: \(identifyTokenString)") - print("๐Ÿšจ", appleIDCredential) - if let bundleID = Bundle.main.bundleIdentifier { - UserDefaults.standard.removePersistentDomain(forName: bundleID) + if let unwrappedFullName = fullName, let givenName = unwrappedFullName.givenName, let familyName = unwrappedFullName.familyName { + UserManager.shared.updateUserName(givenName, familyName) + } else { + print("fullName์ด ์—†๊ฑฐ๋‚˜ givenName ๋˜๋Š” familyName์ด ์—†์Šต๋‹ˆ๋‹ค.") } - // saveToUserDefaults("authorizationCode",keyValue: authorizationCode) - // saveToUserDefaults("identityToken",keyValue: identityToken) - // saveToUserDefaults(authCodeString,keyValue:"authCodeString") - // saveToUserDefaults(identifyTokenString,keyValue:"identifyTokenString") - // saveToUserDefaults("cool",keyValue:"userIdentifier") - + UserManager.shared.updateUserIdentifier(userIdentifier) } - print("useridentifier: \(userIdentifier)") - - - - //Move to MainPage - //let validVC = SignValidViewController() - //validVC.modalPresentationStyle = .fullScreen - //present(validVC, animated: true, completion: nil) - - case let passwordCredential as ASPasswordCredential: - // Sign in using an existing iCloud Keychain credential. - let username = passwordCredential.user - let password = passwordCredential.password - - print("username: \(username)") - print("password: \(password)") + // ๋กœ๊ทธ์ธ์ด ์„ฑ๊ณต ํ•œ๋‹ค๋ฉด + // ์†Œ์…œ ๋กœ๊ทธ์ธ API ์˜๊ธฐ 403 -> ์˜จ๋ณด๋”ฉ ๋ทฐ๋กœ ์ด๋™ + // ํšŒ์› ๊ฐ€์ž…์ด ํ•„์š”ํ•œ์ง€ ์•„๋‹Œ์ง€ ํ™•์ธ, userId๊ฐ€ ์žˆ๋Š”์ง€ ์—†๋Š”์ง€ ํŒ๋ณ„ + // ์œ ์ € ๋ฉ”๋‹ˆ์ €์™€ signInModel์— ํ•ด๋‹น ๊ฐ’ ์ €์žฅ + print(UserManager.shared.getUserIdentifier) + print(UserManager.shared.getUserName) + if (UserManager.shared.appleUserIdentifier != nil) { + let nextViewController = TabBarController() + self.navigationController?.pushViewController(nextViewController, animated: true) + } else { + let nextViewController = TimeSurveyViewController() + self.navigationController?.pushViewController(nextViewController, animated: true) + } + default: break } } - func saveToUserDefaults(_ content: String, keyValue: String) { - // Save the userId to UserDefaults - UserDefaults.standard.set(content, forKey: keyValue) - } - - func authorizationController(controller: ASAuthorizationController, didCompleteWithError error: Error) { // ๋กœ๊ทธ์ธ ์‹คํŒจ(์œ ์ €์˜ ์ทจ์†Œ๋„ ํฌํ•จ) print("login failed - \(error.localizedDescription)") } } + + From 9ef10823824dc3c04b3515e9741e55a4d2fc7a8c Mon Sep 17 00:00:00 2001 From: kim-seonwoo Date: Thu, 11 Jan 2024 17:41:52 +0900 Subject: [PATCH 19/26] =?UTF-8?q?[Feat/#46]=20=EC=95=A0=ED=94=8C=EB=A1=9C?= =?UTF-8?q?=EA=B7=B8=EC=9D=B8=20=ED=83=80=EA=B2=9F=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HMH_iOS/HMH_iOS/HMH_iOS.entitlements | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/HMH_iOS/HMH_iOS/HMH_iOS.entitlements b/HMH_iOS/HMH_iOS/HMH_iOS.entitlements index e048c21..92f5bd8 100644 --- a/HMH_iOS/HMH_iOS/HMH_iOS.entitlements +++ b/HMH_iOS/HMH_iOS/HMH_iOS.entitlements @@ -2,6 +2,10 @@ + com.apple.developer.applesignin + + Default + com.apple.developer.family-controls From ad0cd830812ce8c2a2133815562b010f4d35cabc Mon Sep 17 00:00:00 2001 From: kim-seonwoo Date: Thu, 11 Jan 2024 17:42:33 +0900 Subject: [PATCH 20/26] =?UTF-8?q?[Feat/#46]=20Login=20-=20=EB=A1=9C?= =?UTF-8?q?=EA=B7=B8=EC=9D=B8=20=EB=B7=B0=20=EC=BB=A8=ED=8A=B8=EB=A1=A4?= =?UTF-8?q?=EB=9F=AC=20=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ViewControllers/LoginViewController.swift | 96 ++++++++++++++++++- 1 file changed, 91 insertions(+), 5 deletions(-) diff --git a/HMH_iOS/HMH_iOS/Presentation/Login/ViewControllers/LoginViewController.swift b/HMH_iOS/HMH_iOS/Presentation/Login/ViewControllers/LoginViewController.swift index da57696..42a26ce 100644 --- a/HMH_iOS/HMH_iOS/Presentation/Login/ViewControllers/LoginViewController.swift +++ b/HMH_iOS/HMH_iOS/Presentation/Login/ViewControllers/LoginViewController.swift @@ -13,10 +13,33 @@ import AuthenticationServices final class LoginViewController: UIViewController { let authorizationButton = ASAuthorizationAppleIDButton(authorizationButtonType: .signIn, authorizationButtonStyle: .white) + func setAppleLoginButton() { + authorizationButton.addTarget(self, action: #selector(handleAuthorizationAppleIDButtonPress), for: .touchUpInside) + self.view.addSubview(authorizationButton) + authorizationButton.translatesAutoresizingMaskIntoConstraints = false + } + + @objc + func handleAuthorizationAppleIDButtonPress() { + let appleIDProvider = ASAuthorizationAppleIDProvider() + let request = appleIDProvider.createRequest() + request.requestedScopes = [.fullName, .email] + print(request, "๐Ÿ‘") + let authorizationController = ASAuthorizationController(authorizationRequests: [request]) + authorizationController.delegate = self + authorizationController.presentationContextProvider = self + authorizationController.performRequests() + } + + @objc func appleButtonTaped() { + print("tap") + } + let swipeView = OnboardingSwipeView() override func viewDidLoad() { super.viewDidLoad() + setAppleLoginButton() setUI() } @@ -43,11 +66,74 @@ final class LoginViewController: UIViewController { $0.height.equalTo(480) } } - - private func setAppleLoginButton() { - self.view.addSubview(authorizationButton) - authorizationButton.translatesAutoresizingMaskIntoConstraints = false - } } +extension LoginViewController: ASAuthorizationControllerDelegate, ASAuthorizationControllerPresentationContextProviding{ + func presentationAnchor(for controller: ASAuthorizationController) -> ASPresentationAnchor { + return self.view.window! + } + + func authorizationController(controller: ASAuthorizationController, didCompleteWithAuthorization authorization: ASAuthorization) { + //๋กœ๊ทธ์ธ ์„ฑ๊ณต + switch authorization.credential { + case let appleIDCredential as ASAuthorizationAppleIDCredential: + // You can create an account in your system. + let userIdentifier = appleIDCredential.user + let fullName = appleIDCredential.fullName + let email = appleIDCredential.email + + UserDefaults.standard.set(userIdentifier, forKey: "userIdentifier") + if let authorizationCode = appleIDCredential.authorizationCode, + let identityToken = appleIDCredential.identityToken, + let authCodeString = String(data: authorizationCode, encoding: .utf8), + let identifyTokenString = String(data: identityToken, encoding: .utf8) { + print("authorizationCode: \(authorizationCode)") + print("identityToken: \(identityToken)") + print("authCodeString: \(authCodeString)") + print("identifyTokenString: \(identifyTokenString)") + print("๐Ÿšจ", appleIDCredential) + if let bundleID = Bundle.main.bundleIdentifier { + UserDefaults.standard.removePersistentDomain(forName: bundleID) + } + // saveToUserDefaults("authorizationCode",keyValue: authorizationCode) + // saveToUserDefaults("identityToken",keyValue: identityToken) + // saveToUserDefaults(authCodeString,keyValue:"authCodeString") + // saveToUserDefaults(identifyTokenString,keyValue:"identifyTokenString") + // saveToUserDefaults("cool",keyValue:"userIdentifier") + + } + + print("useridentifier: \(userIdentifier)") + + + + //Move to MainPage + //let validVC = SignValidViewController() + //validVC.modalPresentationStyle = .fullScreen + //present(validVC, animated: true, completion: nil) + + case let passwordCredential as ASPasswordCredential: + // Sign in using an existing iCloud Keychain credential. + let username = passwordCredential.user + let password = passwordCredential.password + + print("username: \(username)") + print("password: \(password)") + + default: + break + } + } + + func saveToUserDefaults(_ content: String, keyValue: String) { + // Save the userId to UserDefaults + UserDefaults.standard.set(content, forKey: keyValue) + } + + + func authorizationController(controller: ASAuthorizationController, didCompleteWithError error: Error) { + // ๋กœ๊ทธ์ธ ์‹คํŒจ(์œ ์ €์˜ ์ทจ์†Œ๋„ ํฌํ•จ) + print("login failed - \(error.localizedDescription)") + } +} From 42a5f156e14a6143b92d180cb1984fabd46983c8 Mon Sep 17 00:00:00 2001 From: kim-seonwoo Date: Thu, 11 Jan 2024 17:43:11 +0900 Subject: [PATCH 21/26] =?UTF-8?q?[Fix/#46]=20SignModel=20-=20=EC=A3=BC?= =?UTF-8?q?=EC=84=9D=20=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Onboarding/Models/SignInModel.swift | 46 +++++++++---------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/HMH_iOS/HMH_iOS/Presentation/Onboarding/Models/SignInModel.swift b/HMH_iOS/HMH_iOS/Presentation/Onboarding/Models/SignInModel.swift index 05871b7..d5d1095 100644 --- a/HMH_iOS/HMH_iOS/Presentation/Onboarding/Models/SignInModel.swift +++ b/HMH_iOS/HMH_iOS/Presentation/Onboarding/Models/SignInModel.swift @@ -5,26 +5,26 @@ // Created by Seonwoo Kim on 1/9/24. // -import Foundation - -struct SignInModel { - let socialPlatform: String - let onboarding: Onboarding - let challenge: Challenge -} - -struct Onboarding { - let averageUseTime: String - let problem: [String] -} - -struct Challenge { - let period: Int - let goalTime: Int - let apps: [Apps] -} - -struct Apps { - let appCode: String - let goalTime: Int -} +//import Foundation +// +//struct SignInModel { +// let socialPlatform: String +// let onboarding: Onboarding +// let challenge: Challenge +//} +// +//struct Onboarding { +// let averageUseTime: String +// let problem: [String] +//} +// +//struct Challenge { +// let period: Int +// let goalTime: Int +// let apps: [Apps] +//} +// +//struct Apps { +// let appCode: String +// let goalTime: Int +//} From dcf661a000415f523bae59a4516970d40212b0ec Mon Sep 17 00:00:00 2001 From: kim-seonwoo Date: Fri, 12 Jan 2024 14:24:17 +0900 Subject: [PATCH 22/26] =?UTF-8?q?[Feat/#46]=20LoginViewController=20-=20?= =?UTF-8?q?=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=EC=84=B1=EA=B3=B5=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ViewControllers/LoginViewController.swift | 51 ++++++++++--------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/HMH_iOS/HMH_iOS/Presentation/Login/ViewControllers/LoginViewController.swift b/HMH_iOS/HMH_iOS/Presentation/Login/ViewControllers/LoginViewController.swift index 42a26ce..a1483b2 100644 --- a/HMH_iOS/HMH_iOS/Presentation/Login/ViewControllers/LoginViewController.swift +++ b/HMH_iOS/HMH_iOS/Presentation/Login/ViewControllers/LoginViewController.swift @@ -12,30 +12,9 @@ import Then import AuthenticationServices final class LoginViewController: UIViewController { - let authorizationButton = ASAuthorizationAppleIDButton(authorizationButtonType: .signIn, authorizationButtonStyle: .white) - func setAppleLoginButton() { - authorizationButton.addTarget(self, action: #selector(handleAuthorizationAppleIDButtonPress), for: .touchUpInside) - self.view.addSubview(authorizationButton) - authorizationButton.translatesAutoresizingMaskIntoConstraints = false - } - @objc - func handleAuthorizationAppleIDButtonPress() { - let appleIDProvider = ASAuthorizationAppleIDProvider() - let request = appleIDProvider.createRequest() - request.requestedScopes = [.fullName, .email] - print(request, "๐Ÿ‘") - let authorizationController = ASAuthorizationController(authorizationRequests: [request]) - authorizationController.delegate = self - authorizationController.presentationContextProvider = self - authorizationController.performRequests() - } - - @objc func appleButtonTaped() { - print("tap") - } - - let swipeView = OnboardingSwipeView() + private let swipeView = OnboardingSwipeView() + let authorizationButton = ASAuthorizationAppleIDButton(authorizationButtonType: .signIn, authorizationButtonStyle: .white) override func viewDidLoad() { super.viewDidLoad() @@ -68,6 +47,32 @@ final class LoginViewController: UIViewController { } } +extension LoginViewController { + + func setAppleLoginButton() { + authorizationButton.addTarget(self, action: #selector(handleAuthorizationAppleIDButtonPress), for: .touchUpInside) + self.view.addSubview(authorizationButton) + authorizationButton.translatesAutoresizingMaskIntoConstraints = false + } + + @objc + func handleAuthorizationAppleIDButtonPress() { + let appleIDProvider = ASAuthorizationAppleIDProvider() + let request = appleIDProvider.createRequest() + request.requestedScopes = [.email] + print(request, "๐Ÿ‘") + let authorizationController = ASAuthorizationController(authorizationRequests: [request]) + authorizationController.delegate = self + authorizationController.presentationContextProvider = self + authorizationController.performRequests() + } + + @objc func appleButtonTaped() { + print("tap") + } + +} + extension LoginViewController: ASAuthorizationControllerDelegate, ASAuthorizationControllerPresentationContextProviding{ func presentationAnchor(for controller: ASAuthorizationController) -> ASPresentationAnchor { From 81541dffd204e6de88aabbed25340a9d2ba7f666 Mon Sep 17 00:00:00 2001 From: kim-seonwoo Date: Fri, 12 Jan 2024 22:34:20 +0900 Subject: [PATCH 23/26] =?UTF-8?q?[Add/#46]=20UserManager=20=ED=8C=8C?= =?UTF-8?q?=EC=9D=BC=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HMH_iOS/HMH_iOS.xcodeproj/project.pbxproj | 16 ++++ .../SupportingFiles/User/UserManager.swift | 90 +++++++++++++++++++ 2 files changed, 106 insertions(+) create mode 100644 HMH_iOS/HMH_iOS/Global/SupportingFiles/User/UserManager.swift diff --git a/HMH_iOS/HMH_iOS.xcodeproj/project.pbxproj b/HMH_iOS/HMH_iOS.xcodeproj/project.pbxproj index 8c6b942..49b6085 100644 --- a/HMH_iOS/HMH_iOS.xcodeproj/project.pbxproj +++ b/HMH_iOS/HMH_iOS.xcodeproj/project.pbxproj @@ -12,6 +12,8 @@ 0B000CED2B4D9DA800AEC582 /* ApprovePermisionController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B000CEC2B4D9DA800AEC582 /* ApprovePermisionController.swift */; }; 0B000CF12B4DA30F00AEC582 /* AppSelectViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B000CF02B4DA30F00AEC582 /* AppSelectViewController.swift */; }; 0B0035402B43D64D00DA140C /* HMHNavigationBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B00353F2B43D64D00DA140C /* HMHNavigationBar.swift */; }; + 0B17D3EB2B5104E000CFA3B7 /* UserManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B17D3EA2B5104E000CFA3B7 /* UserManager.swift */; }; + 0B17D3ED2B5108D200CFA3B7 /* UserDefaultWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B17D3EC2B5108D200CFA3B7 /* UserDefaultWrapper.swift */; }; 0B2C2D3B2B443BE90023CCFA /* Image.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B2C2D3A2B443BE90023CCFA /* Image.swift */; }; 0B2C2D412B4572240023CCFA /* HMHSelectButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B2C2D402B4572240023CCFA /* HMHSelectButton.swift */; }; 0B50F9CB2B369813000C5046 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B50F9CA2B369813000C5046 /* AppDelegate.swift */; }; @@ -174,6 +176,8 @@ 0B000CEC2B4D9DA800AEC582 /* ApprovePermisionController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ApprovePermisionController.swift; sourceTree = ""; }; 0B000CF02B4DA30F00AEC582 /* AppSelectViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppSelectViewController.swift; sourceTree = ""; }; 0B00353F2B43D64D00DA140C /* HMHNavigationBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HMHNavigationBar.swift; sourceTree = ""; }; + 0B17D3EA2B5104E000CFA3B7 /* UserManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserManager.swift; sourceTree = ""; }; + 0B17D3EC2B5108D200CFA3B7 /* UserDefaultWrapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserDefaultWrapper.swift; sourceTree = ""; }; 0B2C2D3A2B443BE90023CCFA /* Image.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Image.swift; sourceTree = ""; }; 0B2C2D402B4572240023CCFA /* HMHSelectButton.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HMHSelectButton.swift; sourceTree = ""; }; 0B50F9C72B369813000C5046 /* HMH_iOS.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = HMH_iOS.app; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -333,6 +337,15 @@ path = ViewControllers; sourceTree = ""; }; + 0B17D3E92B5104B900CFA3B7 /* User */ = { + isa = PBXGroup; + children = ( + 0B17D3EA2B5104E000CFA3B7 /* UserManager.swift */, + 0B17D3EC2B5108D200CFA3B7 /* UserDefaultWrapper.swift */, + ); + path = User; + sourceTree = ""; + }; 0B2C2D3C2B4559AE0023CCFA /* Onboarding */ = { isa = PBXGroup; children = ( @@ -484,6 +497,7 @@ 0B8A89982B369CF800688BA6 /* SupportingFiles */ = { isa = PBXGroup; children = ( + 0B17D3E92B5104B900CFA3B7 /* User */, 3666C8782B45F4D900564874 /* AppBlock */, 0B8A89992B369D0B00688BA6 /* Base */, ); @@ -1073,6 +1087,7 @@ 0B8A89AF2B369E4300688BA6 /* HomeModel.swift in Sources */, 3666C89F2B485C8F00564874 /* DateCollectionViewCell.swift in Sources */, 3666C87A2B45F4F900564874 /* SelectedBlocker.swift in Sources */, + 0B17D3ED2B5108D200CFA3B7 /* UserDefaultWrapper.swift in Sources */, 0BC0EBD42B494459003EF5D4 /* OnboardingSwipeView.swift in Sources */, 17314F9B2B4C485B0089A551 /* UserPointHeaderView.swift in Sources */, 364923862B4FDCBD00BF7ACA /* NetworkProvider.swift in Sources */, @@ -1086,6 +1101,7 @@ 174AF4942B447B5500450D07 /* MyPageViewController.swift in Sources */, 0BA193B42B4D089C007E3F9C /* TimeSurveyViewController.swift in Sources */, 36A3D9B82B3EBC3B007EA272 /* UILabel+.swift in Sources */, + 0B17D3EB2B5104E000CFA3B7 /* UserManager.swift in Sources */, 0B50F9CB2B369813000C5046 /* AppDelegate.swift in Sources */, 0B7817522B4BE0280078E925 /* ProgressBarManager.swift in Sources */, 0B8A89C42B369FA000688BA6 /* F.swift in Sources */, diff --git a/HMH_iOS/HMH_iOS/Global/SupportingFiles/User/UserManager.swift b/HMH_iOS/HMH_iOS/Global/SupportingFiles/User/UserManager.swift new file mode 100644 index 0000000..7b9f626 --- /dev/null +++ b/HMH_iOS/HMH_iOS/Global/SupportingFiles/User/UserManager.swift @@ -0,0 +1,90 @@ +// +// UserManager.swift +// HMH_iOS +// +// Created by Seonwoo Kim on 1/12/24. +// + +import Foundation + +final class UserManager { + static let shared = UserManager() + + @UserDefaultWrapper(key: "accessToken") private(set) var accessToken + @UserDefaultWrapper(key: "refreshToken") private(set) var refreshToken + @UserDefaultWrapper(key: "AppleToken") private(set) var appleToken + @UserDefaultWrapper(key: "userIdentifier") private(set) var appleUserIdentifier + @UserDefaultWrapper(key: "familyName") private(set) var familyName + @UserDefaultWrapper(key: "givenName") private(set) var givenName + @UserDefaultWrapper(key: "fullName") private(set) var fullName + @UserDefaultWrapper(key: "userId") private(set) var userId + + var hasAccessToken: Bool { return self.accessToken != nil } + var getAccessToken: String { return self.accessToken ?? "" } + var getRefreshToken: String { return self.refreshToken ?? "" } + var getAppleToken: String { return self.appleToken ?? "" } + var getUserIdentifier: String { return self.appleUserIdentifier ?? "" } + var getUserName: String { return self.familyName ?? "" } + var getGivenName: String { return self.givenName ?? "" } + var getFullName: String { return self.fullName ?? "" } + var getUserId: Int { return self.userId ?? 0} + + var haveFullName: Bool { + if fullName == "" { + return false + } else if fullName == nil { + return false + } else { + return true + } + } + + private init() {} +} + +extension UserManager { + func updateToken(_ accessToken: String, _ refreshToken: String) { + self.accessToken = accessToken + self.refreshToken = refreshToken + } + + func updateAppleToken(_ appleToken: String) { + self.appleToken = appleToken + } + + func updateUserIdentifier(_ appleUserIdentifier: String) { + self.appleUserIdentifier = appleUserIdentifier + } + + func updateUserName(_ givenName: String, _ familyName: String) { + self.givenName = givenName + self.familyName = familyName + self.fullName = familyName + givenName + } + + func updateUserId(_ userId: Int) { + self.userId = userId + } + + func setUserIdForApple(userId: String) { + self.appleUserIdentifier = appleUserIdentifier + } + + func clearAll() { + self.accessToken = nil + self.refreshToken = nil + self.appleToken = nil + self.appleUserIdentifier = nil + self.familyName = nil + self.givenName = nil + self.fullName = nil + self.userId = nil + } + + func clearData() { + self.accessToken = nil + self.refreshToken = nil + self.appleToken = nil + self.appleUserIdentifier = nil + } +} From b5f690c1e47365c41e11f721874d98b7924c7253 Mon Sep 17 00:00:00 2001 From: kim-seonwoo Date: Fri, 12 Jan 2024 22:35:06 +0900 Subject: [PATCH 24/26] =?UTF-8?q?[Add/#46]=20UserDefaultWrapper=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../User/UserDefaultWrapper.swift | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 HMH_iOS/HMH_iOS/Global/SupportingFiles/User/UserDefaultWrapper.swift diff --git a/HMH_iOS/HMH_iOS/Global/SupportingFiles/User/UserDefaultWrapper.swift b/HMH_iOS/HMH_iOS/Global/SupportingFiles/User/UserDefaultWrapper.swift new file mode 100644 index 0000000..d4c8f86 --- /dev/null +++ b/HMH_iOS/HMH_iOS/Global/SupportingFiles/User/UserDefaultWrapper.swift @@ -0,0 +1,30 @@ +// +// UserDefaultWrapper.swift +// HMH_iOS +// +// Created by Seonwoo Kim on 1/12/24. +// + +import Foundation + +@propertyWrapper +struct UserDefaultWrapper { + + var wrappedValue: T? { + get { + return UserDefaults.standard.object(forKey: self.key) as? T + } + + set { + if newValue == nil { + UserDefaults.standard.removeObject(forKey: key) + } else { UserDefaults.standard.setValue(newValue, forKey: key) } + } + } + + private let key: String + + init(key: String) { + self.key = key + } +} From 9160d14a349cc12e7921b2d998968924e383354b Mon Sep 17 00:00:00 2001 From: kim-seonwoo Date: Fri, 12 Jan 2024 22:42:57 +0900 Subject: [PATCH 25/26] =?UTF-8?q?[Feat/#46]=20SceneDelegate=20-=20?= =?UTF-8?q?=EC=95=A0=ED=94=8C=20=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=EC=9C=A0?= =?UTF-8?q?=EC=A0=80=20=EC=83=81=ED=83=9C=20=EC=A1=B0=ED=9A=8C=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../HMH_iOS/Application/SceneDelegate.swift | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/HMH_iOS/HMH_iOS/Application/SceneDelegate.swift b/HMH_iOS/HMH_iOS/Application/SceneDelegate.swift index 1c5370a..9a3885a 100644 --- a/HMH_iOS/HMH_iOS/Application/SceneDelegate.swift +++ b/HMH_iOS/HMH_iOS/Application/SceneDelegate.swift @@ -6,11 +6,27 @@ // import UIKit +import AuthenticationServices class SceneDelegate: UIResponder, UIWindowSceneDelegate { var window: UIWindow? - + // + func sceneDidBecomeActive(_ scene: UIScene) { + let appleIDProvider = ASAuthorizationAppleIDProvider() + appleIDProvider.getCredentialState(forUserID: "000340.8d411a5d11d84e8da0c22ef43dce465a.1657" ?? "") { (credentialState, error) in + switch credentialState { + case .authorized: + print("authorized") + case .revoked: + print("revoked") + case .notFound: + print("notFound") + default: + break + } + } + } func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) { guard let windowScene = (scene as? UIWindowScene) else { return } @@ -24,7 +40,15 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { DispatchQueue.main.asyncAfter(deadline: .now() + 2) { DispatchQueue.main.async{ - showTabBarViewController() + if UserManager.shared.hasAccessToken { + //์• ํ”Œ ๋กœ๊ทธ์ธ ํ† ํฐ ๋ฆฌํ”„๋ ˆ์‰ฌ ๋กœ์ง. ์„ฑ๊ณตํ•œ๋‹ค๋ฉด ์—‘์„ธ์Šค์™€ ๋ฆฌํ”„๋ ˆ์‹œ ํ† ํฐ ์—…๋ฐ์ดํŠธ ๊ทธ๋Ÿฌ๋ฉด์„œ ์ด๋™ + // ํ† ํฐ ๋ฆฌํ”„๋ ˆ์‹œ๊ฐ€ ์‹คํŒจ ํ•œ๋‹ค. ๋กœ๊ทธ์ธ ์ปจํŠธ๋กค๋Ÿฌ๋กœ ๋ฐ”๋กœ ์ด๋™. +// UserManager.shared.updateToken(,) + + showTabBarViewController() + } else { + showLoginViewController() + } } } From a11549bc42e656d48a2b4b005176662e4c94b291 Mon Sep 17 00:00:00 2001 From: kim-seonwoo Date: Fri, 12 Jan 2024 22:50:25 +0900 Subject: [PATCH 26/26] =?UTF-8?q?[Chore/#46]=20=EC=9E=90=EC=9E=98=ED=95=9C?= =?UTF-8?q?=20=EC=98=A4=EB=A5=98=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SupportingFiles/User/UserManager.swift | 8 +-- .../ViewControllers/LoginViewController.swift | 68 ++++++------------- 2 files changed, 26 insertions(+), 50 deletions(-) diff --git a/HMH_iOS/HMH_iOS/Global/SupportingFiles/User/UserManager.swift b/HMH_iOS/HMH_iOS/Global/SupportingFiles/User/UserManager.swift index 7b9f626..2db9ca3 100644 --- a/HMH_iOS/HMH_iOS/Global/SupportingFiles/User/UserManager.swift +++ b/HMH_iOS/HMH_iOS/Global/SupportingFiles/User/UserManager.swift @@ -47,7 +47,7 @@ extension UserManager { self.accessToken = accessToken self.refreshToken = refreshToken } - + func updateAppleToken(_ appleToken: String) { self.appleToken = appleToken } @@ -55,7 +55,7 @@ extension UserManager { func updateUserIdentifier(_ appleUserIdentifier: String) { self.appleUserIdentifier = appleUserIdentifier } - + func updateUserName(_ givenName: String, _ familyName: String) { self.givenName = givenName self.familyName = familyName @@ -65,11 +65,11 @@ extension UserManager { func updateUserId(_ userId: Int) { self.userId = userId } - + func setUserIdForApple(userId: String) { self.appleUserIdentifier = appleUserIdentifier } - + func clearAll() { self.accessToken = nil self.refreshToken = nil diff --git a/HMH_iOS/HMH_iOS/Presentation/Login/ViewControllers/LoginViewController.swift b/HMH_iOS/HMH_iOS/Presentation/Login/ViewControllers/LoginViewController.swift index a1483b2..3189ce7 100644 --- a/HMH_iOS/HMH_iOS/Presentation/Login/ViewControllers/LoginViewController.swift +++ b/HMH_iOS/HMH_iOS/Presentation/Login/ViewControllers/LoginViewController.swift @@ -59,21 +59,14 @@ extension LoginViewController { func handleAuthorizationAppleIDButtonPress() { let appleIDProvider = ASAuthorizationAppleIDProvider() let request = appleIDProvider.createRequest() - request.requestedScopes = [.email] - print(request, "๐Ÿ‘") + request.requestedScopes = [.fullName] let authorizationController = ASAuthorizationController(authorizationRequests: [request]) authorizationController.delegate = self authorizationController.presentationContextProvider = self authorizationController.performRequests() } - - @objc func appleButtonTaped() { - print("tap") - } - } - extension LoginViewController: ASAuthorizationControllerDelegate, ASAuthorizationControllerPresentationContextProviding{ func presentationAnchor(for controller: ASAuthorizationController) -> ASPresentationAnchor { return self.view.window! @@ -83,62 +76,45 @@ extension LoginViewController: ASAuthorizationControllerDelegate, ASAuthorizatio //๋กœ๊ทธ์ธ ์„ฑ๊ณต switch authorization.credential { case let appleIDCredential as ASAuthorizationAppleIDCredential: - // You can create an account in your system. let userIdentifier = appleIDCredential.user let fullName = appleIDCredential.fullName - let email = appleIDCredential.email - UserDefaults.standard.set(userIdentifier, forKey: "userIdentifier") if let authorizationCode = appleIDCredential.authorizationCode, let identityToken = appleIDCredential.identityToken, let authCodeString = String(data: authorizationCode, encoding: .utf8), let identifyTokenString = String(data: identityToken, encoding: .utf8) { - print("authorizationCode: \(authorizationCode)") - print("identityToken: \(identityToken)") - print("authCodeString: \(authCodeString)") - print("identifyTokenString: \(identifyTokenString)") - print("๐Ÿšจ", appleIDCredential) - if let bundleID = Bundle.main.bundleIdentifier { - UserDefaults.standard.removePersistentDomain(forName: bundleID) + if let unwrappedFullName = fullName, let givenName = unwrappedFullName.givenName, let familyName = unwrappedFullName.familyName { + UserManager.shared.updateUserName(givenName, familyName) + } else { + print("fullName์ด ์—†๊ฑฐ๋‚˜ givenName ๋˜๋Š” familyName์ด ์—†์Šต๋‹ˆ๋‹ค.") } - // saveToUserDefaults("authorizationCode",keyValue: authorizationCode) - // saveToUserDefaults("identityToken",keyValue: identityToken) - // saveToUserDefaults(authCodeString,keyValue:"authCodeString") - // saveToUserDefaults(identifyTokenString,keyValue:"identifyTokenString") - // saveToUserDefaults("cool",keyValue:"userIdentifier") - + UserManager.shared.updateUserIdentifier(userIdentifier) } - print("useridentifier: \(userIdentifier)") - - - - //Move to MainPage - //let validVC = SignValidViewController() - //validVC.modalPresentationStyle = .fullScreen - //present(validVC, animated: true, completion: nil) - - case let passwordCredential as ASPasswordCredential: - // Sign in using an existing iCloud Keychain credential. - let username = passwordCredential.user - let password = passwordCredential.password - - print("username: \(username)") - print("password: \(password)") + // ๋กœ๊ทธ์ธ์ด ์„ฑ๊ณต ํ•œ๋‹ค๋ฉด + // ์†Œ์…œ ๋กœ๊ทธ์ธ API ์˜๊ธฐ 403 -> ์˜จ๋ณด๋”ฉ ๋ทฐ๋กœ ์ด๋™ + // ํšŒ์› ๊ฐ€์ž…์ด ํ•„์š”ํ•œ์ง€ ์•„๋‹Œ์ง€ ํ™•์ธ, userId๊ฐ€ ์žˆ๋Š”์ง€ ์—†๋Š”์ง€ ํŒ๋ณ„ + // ์œ ์ € ๋ฉ”๋‹ˆ์ €์™€ signInModel์— ํ•ด๋‹น ๊ฐ’ ์ €์žฅ + print(UserManager.shared.getUserIdentifier) + print(UserManager.shared.getUserName) + if (UserManager.shared.appleUserIdentifier != nil) { + let nextViewController = TabBarController() + self.navigationController?.pushViewController(nextViewController, animated: true) + } else { + let nextViewController = TimeSurveyViewController() + self.navigationController?.pushViewController(nextViewController, animated: true) + } + default: break } } - func saveToUserDefaults(_ content: String, keyValue: String) { - // Save the userId to UserDefaults - UserDefaults.standard.set(content, forKey: keyValue) - } - - func authorizationController(controller: ASAuthorizationController, didCompleteWithError error: Error) { // ๋กœ๊ทธ์ธ ์‹คํŒจ(์œ ์ €์˜ ์ทจ์†Œ๋„ ํฌํ•จ) print("login failed - \(error.localizedDescription)") } } + +