Skip to content

Commit

Permalink
Merge pull request #68 from AVIRO-official/develop
Browse files Browse the repository at this point in the history
[Ver 1.3.1]
  • Loading branch information
Jeon0976 authored Jul 29, 2024
2 parents e4e0454 + a50dbbb commit 499aac5
Show file tree
Hide file tree
Showing 828 changed files with 4,001 additions and 805 deletions.
778 changes: 769 additions & 9 deletions AVIRO.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Binary file removed AVIRO/AVIRO-PrivacyReport 2024-04-13 14-28-13.pdf
Binary file not shown.
142 changes: 119 additions & 23 deletions AVIRO/App/AppController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ final class AppController {
private let keychain = KeychainSwift()
private let amplitude = AmplitudeUtility()

private let socialLoginUsecase: SocialLoginUseCase

private var window: UIWindow!
private var rootViewController: UIViewController? {
didSet {
Expand All @@ -24,42 +26,81 @@ final class AppController {
}
}

private init() { }
private init() {
let container = DIContainer.shared

self.socialLoginUsecase = SocialLoginUseCase(
appleLoginRepository: container.resolve(AppleAuthRepository.self)!,
googleLoginRepository: container.resolve(GoogleAuthRepository.self)!,
kakaoLoginRepository: container.resolve(KakaoAuthRepository.self)!,
naverLoginRepository: container.resolve(NaverAuthRepository.self)!
)
}

// MARK: 외부랑 소통할 메서드
func show(in window: UIWindow) {
self.window = window
window.backgroundColor = .gray7

checkState()
// setTabBarView()
checkLoginType()
}

func setupLoginViewAfterLogout(in window: UIWindow, with type: LoginViewToastType) {
self.window = window
window.backgroundColor = .gray7

setLoginView(type: type)
}

// MARK: 불러올 view 확인 메서드
private func checkState() {
let userKey = keychain.get(KeychainKey.appleRefreshToken.rawValue)

private func checkLoginType() {
// 최초 튜토리얼 화면 안 봤을 때
guard UserDefaults.standard.bool(forKey: UDKey.tutorial.rawValue) else {
setTutorialView()
return
}

// 자동로그인 토큰 없을 때
guard let userKey = userKey else {

if let loginType = UserDefaults.standard.string(forKey: UDKey.loginType.rawValue) {
switch loginType {
case "apple":
checkMemberFromApple()
case "google", "kakao", "naver":
checkMemberFromOthers()
case "none":
setLoginView()
default:
setLoginView()
}
} else {
// login type 업데이트 전 자동로그인 적용을 위해 사전 작업
if let userKey = keychain.get(KeychainKey.appleRefreshToken.rawValue) {
UserDefaults.standard.set(
LoginTypeKey.apple.rawValue,
forKey: UDKey.loginType.rawValue
)

keychain.set(
userKey,
forKey: KeychainKey.refreshToken.rawValue
)

keychain.delete(KeychainKey.appleRefreshToken.rawValue)

checkMemberFromApple()
} else {
UserDefaults.standard.set(
LoginTypeKey.none.rawValue,
forKey: UDKey.loginType.rawValue
)

setLoginView()
}
}
}

private func checkMemberFromApple() {
keychain.delete(KeychainKey.userID.rawValue)

guard let refreshToken = keychain.get(KeychainKey.refreshToken.rawValue) else {
setLoginView()
return
}

let userCheck = AVIROAutoLoginWhenAppleUserDTO(refreshToken: userKey)

let userCheck = AVIROAutoLoginWhenAppleUserDTO(refreshToken: refreshToken)
AVIROAPI.manager.checkAppleUserWhenInitiate(with: userCheck) { [weak self] result in
DispatchQueue.main.async {
switch result {
Expand All @@ -73,20 +114,61 @@ final class AppController {
userNickname: data.nickname,
marketingAgree: data.marketingAgree
)

self?.setTabBarView()
}
} else {
self?.keychain.delete(KeychainKey.appleRefreshToken.rawValue)
self?.keychain.delete(KeychainKey.refreshToken.rawValue)
self?.setLoginView()
}
case .failure:
self?.keychain.delete(KeychainKey.appleRefreshToken.rawValue)
case .failure(_):
self?.keychain.delete(KeychainKey.refreshToken.rawValue)
self?.setLoginView()
}
}
}
}

private func checkMemberFromOthers() {
keychain.delete(KeychainKey.refreshToken.rawValue)

guard let userID = keychain.get(KeychainKey.userID.rawValue) else {
print("ADAWDAW")
setLoginView()
return
}

let userCheck = AVIROKakaoUserCheckMemberDTO(userId: userID)
print("TSET")
AVIROAPI.manager.checkKakaoUserWhenLogin(with: userCheck) { [weak self] result in
DispatchQueue.main.async {
switch result {
case .success(let model):
if model.statusCode == 200 {
if let data = model.data {
MyData.my.whenLogin(
userId: userID,
userName: "",
userEmail: "",
userNickname: data.nickname,
marketingAgree: data.marketingAgree
)

self?.setTabBarView()
}
} else {
self?.keychain.delete(KeychainKey.userID.rawValue)
self?.setLoginView()
}
case .failure(_):
self?.keychain.delete(KeychainKey.userID.rawValue)
self?.setLoginView()
}
}
}

}

// MARK: tutorial View
private func setTutorialView() {
let tutorialVC = TutorialViewController()
Expand All @@ -97,7 +179,11 @@ final class AppController {
// MARK: login View
private func setLoginView(type: LoginViewToastType = .none) {
let loginVC = LoginViewController()
let presenter = LoginViewPresenter(viewController: loginVC)
let presenter = LoginViewPresenter(
socialLoginUseCase: socialLoginUsecase,
viewController: loginVC
)

loginVC.presenter = presenter

switch type {
Expand Down Expand Up @@ -126,4 +212,14 @@ final class AppController {

rootViewController = tabBarVC
}

func setupLoginViewAfterLogout(
in window: UIWindow,
with type: LoginViewToastType
) {
self.window = window
window.backgroundColor = .gray7

setLoginView(type: type)
}
}
26 changes: 25 additions & 1 deletion AVIRO/App/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
//

import UIKit
import AuthenticationServices
// import AuthenticationServices

import NMapsMap
import AmplitudeSwift
Expand All @@ -23,6 +23,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
self.setNaverMapAPI()
self.setAmplitude()

self.registerRepository()

return true
}

Expand Down Expand Up @@ -73,4 +75,26 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

amplitude = Amplitude(configuration: Configuration(apiKey: key))
}

private func registerRepository() {
DIContainer.shared.register(
AppleAuthRepository.self,
dependency: AppleAuthRepository()
)

DIContainer.shared.register(
GoogleAuthRepository.self,
dependency: GoogleAuthRepository()
)

DIContainer.shared.register(
KakaoAuthRepository.self,
dependency: KakaoAuthRepository()
)

DIContainer.shared.register(
NaverAuthRepository.self,
dependency: NaverAuthRepository()
)
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
34 changes: 34 additions & 0 deletions AVIRO/App/DIContainer.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// DIContainer.swift
// AVIRO
//
// Created by 전성훈 on 5/10/24.
//

import Foundation

final class DIContainer {
static let shared = DIContainer()

private var dependencies: [String: AnyObject] = [:]

private init() { }

func register<T: AnyObject>(_ type: T.Type, dependency: T) {
let key = String(describing: type)

dependencies[key] = dependency
}

func resolve<T: AnyObject>(_ type: T.Type) -> T? {
let key = String(describing: type)

guard let value = dependencies[key] as? T else {
printIfDebug("---- 의존성 key 값을 찾지 못했습니다 \(key) ----")

return nil
}

return value
}
}
38 changes: 38 additions & 0 deletions AVIRO/App/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,48 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleGetInfoString</key>
<string></string>
<key>CFBundleLocalizations</key>
<array>
<string>ko</string>
</array>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<string>com.googleusercontent.apps.310817462771-q5o6bv76a0os9lgqaqfico9jomv7fvkc</string>
</array>
</dict>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<string>com.aviro.ios</string>
</array>
</dict>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<string>kakaoa880a81ee8796717e8d6e517630fff5d</string>
</array>
</dict>
</array>
<key>GIDClientID</key>
<string>310817462771-q5o6bv76a0os9lgqaqfico9jomv7fvkc.apps.googleusercontent.com</string>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>kakaokompassauth</string>
<string>kakaolink</string>
<string>naversearchapp</string>
<string>naversearchthridlogin</string>
</array>
<key>UIAppFonts</key>
<array>
<string>Pretendard-Black.otf</string>
Expand Down
29 changes: 29 additions & 0 deletions AVIRO/App/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

import UIKit

import NaverThirdPartyLogin
import KakaoSDKAuth
import GoogleSignIn

class SceneDelegate: UIResponder, UIWindowSceneDelegate {

var window: UIWindow?
Expand All @@ -32,4 +36,29 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
}
}
}

func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) {
guard let urlContext = URLContexts.first else { return }
let url = urlContext.url
print(url)

// Naver
if url.scheme == "com.aviro.ios" {
NaverThirdPartyLoginConnection
.getSharedInstance()
.receiveAccessToken(url)

return
}

// Kakao
if AuthApi.isKakaoTalkLoginUrl(url) {
_ = AuthController.handleOpenUrl(url: url)

return
}

// Google
GIDSignIn.sharedInstance.handle(url)
}
}
12 changes: 12 additions & 0 deletions AVIRO/Common/Cancellable.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// Cancellable.swift
// AVIRO
//
// Created by 전성훈 on 7/6/24.
//

import Foundation

protocol Cancellable {
func cancel()
}
12 changes: 12 additions & 0 deletions AVIRO/Common/printIfDebug.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// printIfDebug.swift
// AVIRO
//
// Created by 전성훈 on 5/10/24.
//

func printIfDebug(_ string: String) {
#if DEBUG
print(string)
#endif
}
Loading

0 comments on commit 499aac5

Please sign in to comment.