Skip to content

Commit

Permalink
[FEAT] #167 - 애플 로그인 이미지와 스플래시 자동 로그인 처리는 우선 주석으로 표기
Browse files Browse the repository at this point in the history
  • Loading branch information
mini-min committed Dec 21, 2021
1 parent 3b42fd1 commit 6258243
Show file tree
Hide file tree
Showing 10 changed files with 93 additions and 48 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"images" : [
{
"filename" : "AppleLogin.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"filename" : "AppleLogin-1.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "AppleLogin@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"filename" : "AppleLogin-1@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "AppleLogin@3x.png",
"idiom" : "universal",
"scale" : "3x"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"filename" : "AppleLogin-1@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
</imageView>
<stackView opaque="NO" contentMode="scaleToFill" axis="vertical" distribution="fillEqually" spacing="14" translatesAutoresizingMaskIntoConstraints="NO" id="Bjc-le-F1v">
<rect key="frame" x="24" y="558" width="327" height="110"/>
<color key="backgroundColor" name="background"/>
<constraints>
<constraint firstAttribute="height" constant="110" id="zMJ-VE-Guw"/>
</constraints>
Expand Down
26 changes: 25 additions & 1 deletion NADA-iOS-forRelease/Sources/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@

import UIKit
import KakaoSDKCommon
import AuthenticationServices

@main
class AppDelegate: UIResponder, UIApplicationDelegate {

var isLogin = false

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
Expand All @@ -20,6 +21,29 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
if UserDefaults.standard.string(forKey: Const.UserDefaults.accessToken) != nil {
isLogin = true
}

// let appleIDProvider = ASAuthorizationAppleIDProvider()
// appleIDProvider.getCredentialState(forUserID: Const.UserDefaults.userID) { (credentialState, error) in
// switch credentialState {
// case .authorized:
// print("해당 ID는 연동되어있습니다.")
// self.isLogin = true
// case .revoked:
// print("해당 ID는 연동되어있지않습니다.")
// self.isLogin = false
// case .notFound:
// print("해당 ID를 찾을 수 없습니다.")
// self.isLogin = false
// default:
// break
// }
// }

NotificationCenter.default.addObserver(forName: ASAuthorizationAppleIDProvider.credentialRevokedNotification, object: nil, queue: nil) { (Notification) in
print("Revoked Notification")
self.isLogin = false
}

return true
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@ class LoginViewController: UIViewController {
super.viewDidLoad()

setUI()
// FIXME: - 서버 연결 테스트, 추후 위치 수정 필요
// getUserIDFetchWithAPI(userID: "nada")
// getUserTokenFetchWithAPI(userID: "nada")
}

// MARK: - Functions
func setUI() {
let kakaoButton = UIButton()
kakaoButton.setImage(UIImage(named: "kakao_login_large_wide"), for: .normal)
kakaoButton.cornerRadius = 15
kakaoButton.addTarget(self, action: #selector(kakaoSignInButtonPress), for: .touchUpInside)
loginProviderStackView.addSubview(kakaoButton)

Expand All @@ -42,6 +40,8 @@ class LoginViewController: UIViewController {
])

let authorizationButton = ASAuthorizationAppleIDButton(type: .signIn, style: .black)
// let authorizationButton = UIButton()
// authorizationButton.setImage(UIImage(named: "appleLogin"), for: .normal)
authorizationButton.addTarget(self, action: #selector(appleSignInButtonPress), for: .touchUpInside)
loginProviderStackView.addSubview(authorizationButton)

Expand Down Expand Up @@ -100,7 +100,7 @@ class LoginViewController: UIViewController {
// MARK: - KakaoSignIn
extension LoginViewController {
func loginWithApp() {
UserApi.shared.loginWithKakaoTalk {(oauthToken, error) in
UserApi.shared.loginWithKakaoTalk {(_, error) in
if let error = error {
print(error)
} else {
Expand All @@ -123,7 +123,7 @@ extension LoginViewController {
}

func loginWithWeb() {
UserApi.shared.loginWithKakaoAccount {(oauthToken, error) in
UserApi.shared.loginWithKakaoAccount {(_, error) in
if let error = error {
print(error)
} else {
Expand Down Expand Up @@ -166,17 +166,16 @@ extension LoginViewController: ASAuthorizationControllerDelegate, ASAuthorizatio
// Apple ID 연동 성공 시
func authorizationController(controller: ASAuthorizationController, didCompleteWithAuthorization authorization: ASAuthorization) {
switch authorization.credential {
// Apple ID
// Apple ID
case let appleIDCredential as ASAuthorizationAppleIDCredential:

// 계정 정보 가져오기
let userIdentifier = appleIDCredential.user
let fullName = appleIDCredential.fullName
let email = appleIDCredential.email
// let fullName = appleIDCredential.fullName
// let email = appleIDCredential.email

print("User ID : \(userIdentifier)")
print("User Email : \(email ?? "")")
print("User Name : \((fullName?.givenName ?? "") + (fullName?.familyName ?? ""))")
// print("User ID : \(userIdentifier)")
// print("User Email : \(email ?? "")")
// print("User Name : \((fullName?.givenName ?? "") + (fullName?.familyName ?? ""))")
postUserSignUpWithAPI(request: userIdentifier)
presentToMain()

Expand All @@ -193,47 +192,12 @@ extension LoginViewController: ASAuthorizationControllerDelegate, ASAuthorizatio

// MARK: - Network
extension LoginViewController {
func getUserIDFetchWithAPI(userID: String) {
UserAPI.shared.userIDFetch(userID: userID) { response in
switch response {
case .success(let data):
print(data)
case .requestErr(let message):
print("getUserIDFetchWithAPI - requestErr", message)
case .pathErr:
print("getUserIDFetchWithAPI - pathErr")
case .serverErr:
print("getUserIDFetchWithAPI - serverErr")
case .networkFail:
print("getUserIDFetchWithAPI - networkFail")
}
}
}

func getUserTokenFetchWithAPI(userID: String) {
UserAPI.shared.userTokenFetch(userID: userID) { response in
switch response {
case .success(let data):
print(data)
case .requestErr(let message):
print("getUserTokenFetchWithAPI - requestErr", message)
case .pathErr:
print("getUserTokenFetchWithAPI - pathErr")
case .serverErr:
print("getUserTokenFetchWithAPI - serverErr")
case .networkFail:
print("getUserTokenFetchWithAPI - networkFail")
}
}
}

func postUserSignUpWithAPI(request: String) {
UserAPI.shared.userSocialSignUp(request: request) { response in
switch response {
case .success(let loginData):
print("postUserSignUpWithAPI - success")
if let userData = loginData as? UserWithTokenRequest {
print(userData.user.userID, "⭐️")
UserDefaults.standard.set(userData.user.userID, forKey: Const.UserDefaults.userID)
if let tokenData = userData.user.token as? Token {
UserDefaults.standard.set(tokenData.accessToken, forKey: Const.UserDefaults.accessToken)
Expand Down

0 comments on commit 6258243

Please sign in to comment.