From 8c3877cfa220c5e2369262acd04bfc543b7ea599 Mon Sep 17 00:00:00 2001 From: ryr0121 Date: Wed, 15 Mar 2023 20:44:47 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EA=B5=AC=EA=B8=80=20=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EC=9D=B8=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- KeKi.xcodeproj/project.pbxproj | 20 +++++++++ KeKi/App/AppDelegate.swift | 5 +++ KeKi/App/SceneDelegate.swift | 6 +++ KeKi/Info.plist | 10 ++++- KeKi/Scenes/Login/LoginViewController.swift | 49 +++++++++++++++++++-- Podfile | 1 + Podfile.lock | 25 ++++++++++- 7 files changed, 109 insertions(+), 7 deletions(-) diff --git a/KeKi.xcodeproj/project.pbxproj b/KeKi.xcodeproj/project.pbxproj index 9d734a3..0151edb 100644 --- a/KeKi.xcodeproj/project.pbxproj +++ b/KeKi.xcodeproj/project.pbxproj @@ -611,6 +611,7 @@ A2434AC3298651F500F60D1A /* Frameworks */, A2434AC4298651F500F60D1A /* Resources */, 1B90B7F2C8B7B75310385F93 /* [CP] Embed Pods Frameworks */, + D8120C1246AF0D85A8F0061A /* [CP] Copy Pods Resources */, ); buildRules = ( ); @@ -741,6 +742,23 @@ shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-KeKi/Pods-KeKi-frameworks.sh\"\n"; showEnvVarsInLog = 0; }; + D8120C1246AF0D85A8F0061A /* [CP] Copy Pods Resources */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + "${PODS_ROOT}/Target Support Files/Pods-KeKi/Pods-KeKi-resources-${CONFIGURATION}-input-files.xcfilelist", + ); + name = "[CP] Copy Pods Resources"; + outputFileListPaths = ( + "${PODS_ROOT}/Target Support Files/Pods-KeKi/Pods-KeKi-resources-${CONFIGURATION}-output-files.xcfilelist", + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-KeKi/Pods-KeKi-resources.sh\"\n"; + showEnvVarsInLog = 0; + }; DE60C26EFAE342A4F9F45506 /* [CP] Check Pods Manifest.lock */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; @@ -1001,6 +1019,7 @@ INFOPLIST_KEY_UIMainStoryboardFile = ""; INFOPLIST_KEY_UISupportedInterfaceOrientations = UIInterfaceOrientationPortrait; INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown"; + INFOPLIST_KEY_UIUserInterfaceStyle = Light; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", @@ -1036,6 +1055,7 @@ INFOPLIST_KEY_UIMainStoryboardFile = ""; INFOPLIST_KEY_UISupportedInterfaceOrientations = UIInterfaceOrientationPortrait; INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown"; + INFOPLIST_KEY_UIUserInterfaceStyle = Light; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", diff --git a/KeKi/App/AppDelegate.swift b/KeKi/App/AppDelegate.swift index fe69572..1f49859 100644 --- a/KeKi/App/AppDelegate.swift +++ b/KeKi/App/AppDelegate.swift @@ -16,6 +16,8 @@ import NaverThirdPartyLogin import AuthenticationServices +import GoogleSignIn + @main class AppDelegate: UIResponder, UIApplicationDelegate { @@ -38,6 +40,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate { instance?.consumerSecret = "XZHzyRgQditsj_BuDAHZ" // pw instance?.appName = "케키" // app name + // Google + GIDSignIn.sharedInstance().clientID = "282823038399-jp07tva2mg6o0amv7hrm1relkockop3r.apps.googleusercontent.com" + // Loacl Notification let center = UNUserNotificationCenter.current() // 알림 센터 가져오기 diff --git a/KeKi/App/SceneDelegate.swift b/KeKi/App/SceneDelegate.swift index ae034ec..d65d61f 100644 --- a/KeKi/App/SceneDelegate.swift +++ b/KeKi/App/SceneDelegate.swift @@ -8,6 +8,7 @@ import UIKit import KakaoSDKAuth import NaverThirdPartyLogin +import GoogleSignIn class SceneDelegate: UIResponder, UIWindowSceneDelegate { @@ -39,6 +40,11 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate { .getSharedInstance()? .receiveAccessToken(URLContexts.first?.url) } + + guard let scheme = URLContexts.first?.url.scheme else { return } + if scheme.contains("com.googleusercontent.apps") { + GIDSignIn.sharedInstance().handle(URLContexts.first?.url) + } } } diff --git a/KeKi/Info.plist b/KeKi/Info.plist index e3754bd..dd732b9 100644 --- a/KeKi/Info.plist +++ b/KeKi/Info.plist @@ -2,8 +2,6 @@ - UIUserInterfaceStyle - Light CFBundleURLTypes @@ -24,6 +22,14 @@ https://keki-dev.store/users/callback/naver + + CFBundleTypeRole + Editor + CFBundleURLSchemes + + com.googleusercontent.apps.282823038399-jp07tva2mg6o0amv7hrm1relkockop3r + + KAKAO_NATIVE_APP_KEY ${KAKAO_NATIVE_APP_KEY} diff --git a/KeKi/Scenes/Login/LoginViewController.swift b/KeKi/Scenes/Login/LoginViewController.swift index bd5d696..33f793a 100644 --- a/KeKi/Scenes/Login/LoginViewController.swift +++ b/KeKi/Scenes/Login/LoginViewController.swift @@ -13,6 +13,7 @@ import KakaoSDKAuth import KakaoSDKUser import NaverThirdPartyLogin import AuthenticationServices +import GoogleSignIn enum Role: String { case notUser = "비회원" @@ -28,7 +29,7 @@ class LoginViewController: UIViewController { // MARK: - Variables, IBOutlet, ... let naverLoginInstance = NaverThirdPartyLoginConnection.getSharedInstance() - @IBOutlet weak var googleLoginButton: UIButton! + @IBOutlet weak var googleLoginButton: GIDSignInButton! @IBOutlet weak var kakaoLoginButton: UIButton! @IBOutlet weak var naverLoginButton: UIButton! @IBOutlet weak var appleLoginButton: ASAuthorizationAppleIDButton! @@ -43,6 +44,9 @@ class LoginViewController: UIViewController { // apple login button setup appleLoginButton.addTarget(self, action: #selector(didTapAppleLoginButton(_:)), for: .touchUpInside) + + // google login setup + setGoogleSignInButton() } override func viewWillAppear(_ animated: Bool) { @@ -54,10 +58,11 @@ class LoginViewController: UIViewController { @IBAction func didTapGoogleLoginButton(_ sender: UIButton) { // TODO: 구글 로그인 기능 추가 print("didTapGoogleLoginButton") + googleSocialLogin() // 유저 정보 설정창으로 전환 처리 (임시 구현, 이후 삭제 예정) - guard let selectUserCategoryViewController = storyboard?.instantiateViewController(withIdentifier: "SelectUserCategoryViewController") as? SelectUserCategoryViewController else { return } - navigationController?.pushViewController(selectUserCategoryViewController, animated: true) +// guard let selectUserCategoryViewController = storyboard?.instantiateViewController(withIdentifier: "SelectUserCategoryViewController") as? SelectUserCategoryViewController else { return } +// navigationController?.pushViewController(selectUserCategoryViewController, animated: true) } @IBAction func didTapKakaoLoginButton(_ sender: UIButton) { @@ -80,6 +85,11 @@ class LoginViewController: UIViewController { // MARK: - Helper Methods (Setup Method, ...) + private func setGoogleSignInButton() { + GIDSignIn.sharedInstance()?.presentingViewController = self + GIDSignIn.sharedInstance().delegate = self + } + private func setupButtonLayouts() { [ googleLoginButton, @@ -96,7 +106,7 @@ class LoginViewController: UIViewController { appleLoginButton ].forEach { $0?.layer.cornerRadius = 25 } - googleLoginButton.configuration?.imagePadding = 53 +// googleLoginButton.configuration?.imagePadding = 53 kakaoLoginButton.configuration?.imagePadding = 53 naverLoginButton.configuration?.imagePadding = 34 // appleLoginButton.configuration?.imagePadding = 48 @@ -123,6 +133,33 @@ class LoginViewController: UIViewController { } } +// MARK: - GOOGLE Social Login Delegate +extension LoginViewController: GIDSignInDelegate { + func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) { + if let error = error { + if (error as NSError).code == GIDSignInErrorCode.hasNoAuthInKeychain.rawValue { + print("The user has not signed in before or they have since signed out.") + } else { + print("\(error.localizedDescription)") + } + return + } + + // 사용자 정보 가져오기 + if let email = user.profile.email { + print("User Email : \(email)") + requestSocialLogin(email: email, provider: "구글") + + } else { + print("Error : User Data Not Found") + } + } + + func oauth20Connection(_ oauthConnection: NaverThirdPartyLoginConnection!, didFinishAuthorizationWithResult receiveType: THIRDPARTYLOGIN_RECEIVE_TYPE) { + print("Google Login Disconnect") + } +} + // MARK: - NAVER Social Login Delegate extension LoginViewController : NaverThirdPartyLoginConnectionDelegate { func oauth20ConnectionDidFinishRequestACTokenWithAuthCode() { getNaverUserInfo() } @@ -204,6 +241,10 @@ extension LoginViewController { authorizationController.presentationContextProvider = self authorizationController.performRequests() } + + private func googleSocialLogin() { + GIDSignIn.sharedInstance()?.signIn() + } } extension LoginViewController { diff --git a/Podfile b/Podfile index d621302..1cae00b 100644 --- a/Podfile +++ b/Podfile @@ -9,5 +9,6 @@ target 'KeKi' do pod 'IQKeyboardManagerSwift' pod 'naveridlogin-sdk-ios' pod 'JGProgressHUD' + pod 'GoogleSignIn', '~> 5.0' end diff --git a/Podfile.lock b/Podfile.lock index 8630fc9..979a3a4 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -1,24 +1,47 @@ PODS: + - AppAuth (1.6.0): + - AppAuth/Core (= 1.6.0) + - AppAuth/ExternalUserAgent (= 1.6.0) + - AppAuth/Core (1.6.0) + - AppAuth/ExternalUserAgent (1.6.0): + - AppAuth/Core + - GoogleSignIn (5.0.2): + - AppAuth (~> 1.2) + - GTMAppAuth (~> 1.0) + - GTMSessionFetcher/Core (~> 1.1) + - GTMAppAuth (1.3.1): + - AppAuth/Core (~> 1.6) + - GTMSessionFetcher/Core (< 3.0, >= 1.5) + - GTMSessionFetcher/Core (1.7.2) - IQKeyboardManagerSwift (6.5.11) - JGProgressHUD (2.2) - naveridlogin-sdk-ios (4.1.5) DEPENDENCIES: + - GoogleSignIn (~> 5.0) - IQKeyboardManagerSwift - JGProgressHUD - naveridlogin-sdk-ios SPEC REPOS: trunk: + - AppAuth + - GoogleSignIn + - GTMAppAuth + - GTMSessionFetcher - IQKeyboardManagerSwift - JGProgressHUD - naveridlogin-sdk-ios SPEC CHECKSUMS: + AppAuth: 8fca6b5563a5baef2c04bee27538025e4ceb2add + GoogleSignIn: 7137d297ddc022a7e0aa4619c86d72c909fa7213 + GTMAppAuth: 0ff230db599948a9ad7470ca667337803b3fc4dd + GTMSessionFetcher: 5595ec75acf5be50814f81e9189490412bad82ba IQKeyboardManagerSwift: c7955c0bdbf7b2eb29bb7daaa44e3d90f55a9a85 JGProgressHUD: d83d7a981b85d11205e19ff8ad5bb9c40571c847 naveridlogin-sdk-ios: 4351fe7162cd6b8b6dbb37bd7cc205304fa1d889 -PODFILE CHECKSUM: b1c2d7472062cbb78bb5f4a1496c6b7905de1861 +PODFILE CHECKSUM: 9c54f882dc5ba1f159bbd41025044f1fc34fe4c0 COCOAPODS: 1.11.3