diff --git a/pophory-iOS.xcodeproj/project.pbxproj b/pophory-iOS.xcodeproj/project.pbxproj index e233e1a7..d240383d 100644 --- a/pophory-iOS.xcodeproj/project.pbxproj +++ b/pophory-iOS.xcodeproj/project.pbxproj @@ -759,15 +759,6 @@ path = ViewController; sourceTree = ""; }; - 3B218EA52B833F85006959E3 /* Interceptor */ = { - isa = PBXGroup; - children = ( - 3B218EA62B833FA0006959E3 /* AuthInterceptor.swift */, - ); - name = Interceptor; - path = "Intercep색"; - sourceTree = ""; - }; 3B3A090F2A56A4F200C8A740 /* PhotoDetail */ = { isa = PBXGroup; children = ( @@ -816,6 +807,14 @@ path = ViewModel; sourceTree = ""; }; + 3BC15D842C6255BC0056A87F /* Interceptor */ = { + isa = PBXGroup; + children = ( + 3B218EA62B833FA0006959E3 /* AuthInterceptor.swift */, + ); + path = Interceptor; + sourceTree = ""; + }; 3BE178932C4FF1A600FC755B /* View */ = { isa = PBXGroup; children = ( @@ -1006,7 +1005,7 @@ 91F3A77C2A52AD8300C06D1B /* Network */ = { isa = PBXGroup; children = ( - 3B218EA52B833F85006959E3 /* Interceptor */, + 3BC15D842C6255BC0056A87F /* Interceptor */, 91F3A77D2A52ADCA00C06D1B /* Common */, B1631F5E2A175FD00050974F /* Models */, 91F3A78A2A52B1B300C06D1B /* API */, diff --git a/pophory-iOS/Global/Resources/Assets.xcassets/ErrorImg/networkFail.imageset/Contents.json b/pophory-iOS/Global/Resources/Assets.xcassets/ErrorImg/networkFail.imageset/Contents.json index 3b467a25..a0f2f06d 100644 --- a/pophory-iOS/Global/Resources/Assets.xcassets/ErrorImg/networkFail.imageset/Contents.json +++ b/pophory-iOS/Global/Resources/Assets.xcassets/ErrorImg/networkFail.imageset/Contents.json @@ -1,7 +1,7 @@ { "images" : [ { - "filename" : "Frame 514631.pdf", + "filename" : "img_networkError.svg", "idiom" : "universal" } ], diff --git a/pophory-iOS/Global/Resources/Assets.xcassets/ErrorImg/networkFail.imageset/Frame 514631.pdf b/pophory-iOS/Global/Resources/Assets.xcassets/ErrorImg/networkFail.imageset/Frame 514631.pdf deleted file mode 100644 index a7244391..00000000 Binary files a/pophory-iOS/Global/Resources/Assets.xcassets/ErrorImg/networkFail.imageset/Frame 514631.pdf and /dev/null differ diff --git a/pophory-iOS/Global/Resources/Assets.xcassets/ErrorImg/networkFail.imageset/img_networkError.svg b/pophory-iOS/Global/Resources/Assets.xcassets/ErrorImg/networkFail.imageset/img_networkError.svg new file mode 100644 index 00000000..a2c12283 --- /dev/null +++ b/pophory-iOS/Global/Resources/Assets.xcassets/ErrorImg/networkFail.imageset/img_networkError.svg @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/pophory-iOS/Global/Resources/SceneDelegate.swift b/pophory-iOS/Global/Resources/SceneDelegate.swift index 182f01fc..88ccea6c 100644 --- a/pophory-iOS/Global/Resources/SceneDelegate.swift +++ b/pophory-iOS/Global/Resources/SceneDelegate.swift @@ -177,9 +177,9 @@ extension SceneDelegate { let window = UIWindow(windowScene: windowScene) window.overrideUserInterfaceStyle = .light - RootViewSwitcher.shared.setWindow(window) + self.window = window + window.makeKeyAndVisible() + RootViewSwitcher.shared.setRootView(.splash) - - self.window = window } } diff --git a/pophory-iOS/Global/Utilities/RootViewSwitcher.swift b/pophory-iOS/Global/Utilities/RootViewSwitcher.swift index bad62103..c993e4f8 100644 --- a/pophory-iOS/Global/Utilities/RootViewSwitcher.swift +++ b/pophory-iOS/Global/Utilities/RootViewSwitcher.swift @@ -7,21 +7,20 @@ import UIKit -enum RootView { - case splash - case onboarding - case home - case albumFull - case addPhoto(image: UIImage, imageType: PhotoCellType) - case share(shareId: String) -} - enum UpdateType { case force case optional } final class RootViewSwitcher { + enum RootView { + case splash + case onboarding + case home + case albumFull + case addPhoto(image: UIImage, imageType: PhotoCellType) + case share(shareId: String) + } static let shared = RootViewSwitcher() @@ -41,8 +40,9 @@ final class RootViewSwitcher { extension RootViewSwitcher { func setRootView(_ rootView: RootView) { - guard let window = self.window else { return } - + let sceneDelegate = UIApplication.shared.connectedScenes.first?.delegate as? SceneDelegate + guard let delegate = sceneDelegate else { return } + var rootViewController: UIViewController switch rootView { case .splash: @@ -74,7 +74,6 @@ extension RootViewSwitcher { navigationController.pushViewController(addPhotoViewController, animated: false) return } - window.rootViewController = PophoryNavigationController(rootViewController: rootViewController) - window.makeKeyAndVisible() + delegate.window?.rootViewController = PophoryNavigationController(rootViewController: rootViewController) } } diff --git a/pophory-iOS/Network/Interceptor/AuthInterceptor.swift b/pophory-iOS/Network/Interceptor/AuthInterceptor.swift new file mode 100644 index 00000000..cda5a1b7 --- /dev/null +++ b/pophory-iOS/Network/Interceptor/AuthInterceptor.swift @@ -0,0 +1,65 @@ +// +// File.swift +// pophory-iOS +// +// Created by 강윤서 on 2/19/24. +// + +import Foundation +import Alamofire + +final class AuthInterceptor: RequestInterceptor { + + static let shared = AuthInterceptor() + + private init() {} + + func adapt(_ urlRequest: URLRequest, for session: Session, completion: @escaping (Result) -> Void) { + guard let urlString = Bundle.main.infoDictionary?["BASE_URL"] as? String, + let url = URL(string: urlString) else { + fatalError("🚨Base URL을 찾을 수 없습니다🚨") + } + + guard urlRequest.url?.absoluteString.hasPrefix(urlString) == true, + let accessToken = PophoryTokenManager.shared.fetchAccessToken(), + let refreshToken = PophoryTokenManager.shared.fetchRefreshToken() else { + completion(.success(urlRequest)) + return + } + + var urlRequest = urlRequest + urlRequest.setValue("Bearer \(PophoryTokenManager.shared.fetchAccessToken()!)", forHTTPHeaderField: "Authorization") +// urlRequest.headers.update(name: "Authorization", value: "Bearer \(PophoryTokenManager.shared.fetchAccessToken()!)") + print("🍥🍥🍥adator 적용 \(urlRequest.headers)") + completion(.success(urlRequest)) + } + + func retry(_ request: Request, for session: Session, dueTo error: Error, completion: @escaping (RetryResult) -> Void) { + print("🍥🍥🍥retry 진입") + guard let response = request.task?.response as? HTTPURLResponse, response.statusCode == 401 else { + completion(.doNotRetryWithError(error)) + return + } + + NetworkService.shared.authRepostiory.updateRefreshToken { result in + switch result { + case .success(let response): + guard let data = response as? UpdatedAccessTokenDTO else { + DispatchQueue.main.async { + RootViewSwitcher.shared.setRootView(.onboarding) + } + completion(.doNotRetryWithError(error)) + return + } + PophoryTokenManager.shared.saveAccessToken(data.accessToken) + PophoryTokenManager.shared.saveRefreshToken(data.refreshToken) + completion(.retry) + default: + DispatchQueue.main.async { + RootViewSwitcher.shared.setRootView(.onboarding) + } + completion(.doNotRetryWithError(error)) + } + } + } +} diff --git "a/pophory-iOS/Network/Intercep\354\203\211/AuthInterceptor.swift" "b/pophory-iOS/Network/Intercep\354\203\211/AuthInterceptor.swift" deleted file mode 100644 index d2535614..00000000 --- "a/pophory-iOS/Network/Intercep\354\203\211/AuthInterceptor.swift" +++ /dev/null @@ -1,53 +0,0 @@ -// -// File.swift -// pophory-iOS -// -// Created by 강윤서 on 2/19/24. -// - -import Foundation -import Alamofire - -final class AuthInterceptor: RequestInterceptor { - - static let shared = AuthInterceptor() - - private init() {} - - func adapt(_ urlRequest: URLRequest, for session: Session, completion: @escaping (Result) -> Void) { - guard urlRequest.url?.absoluteString.hasPrefix(Bundle.baseURL) == true, - let accessToken = PophoryTokenManager.shared.fetchAccessToken() else { - completion(.success(urlRequest)) - return - } - var urlRequest = urlRequest - urlRequest.addValue(accessToken, forHTTPHeaderField: "accessToken") - print("🍥🍥🍥adat 적용 \(urlRequest.headers)") - completion(.success(urlRequest)) - } - - func retry(_ request: Request, for session: Session, dueTo error: Error, completion: @escaping (RetryResult) -> Void) { - print("🍥🍥🍥retry 진입") - guard let response = request.task?.response as? HTTPURLResponse, - response.statusCode == 401 else { - RootViewSwitcher.shared.setRootView(.onboarding) - completion(.doNotRetryWithError(error)) - return - } - - NetworkService.shared.authRepostiory.updateRefreshToken { result in - switch result { - case .success(let response): - guard let response = response as? UpdatedAccessTokenDTO else { - RootViewSwitcher.shared.setRootView(.onboarding) - completion(.doNotRetryWithError(error)) - return - } - completion(.retry) - default: - RootViewSwitcher.shared.setRootView(.onboarding) - completion(.doNotRetryWithError(error)) - } - } - } -} diff --git a/pophory-iOS/Network/Repository/DefaultAuthRepository.swift b/pophory-iOS/Network/Repository/DefaultAuthRepository.swift index f73bda12..52a46973 100644 --- a/pophory-iOS/Network/Repository/DefaultAuthRepository.swift +++ b/pophory-iOS/Network/Repository/DefaultAuthRepository.swift @@ -63,9 +63,7 @@ final class DefaultAuthRepository: BaseRepository, AuthRepository { if response.statusCode < 300 { do { let loginResponse = try response.map(UpdatedAccessTokenDTO.self) - completion(.success((loginResponse))) - PophoryTokenManager.shared.saveAccessToken(loginResponse.accessToken) - PophoryTokenManager.shared.saveRefreshToken(loginResponse.refreshToken) + completion(.success((loginResponse))) print("Successfully refreshed access token") } catch { print("Error decoding the login response: \(error)") diff --git a/pophory-iOS/Screen/Auth/ViewControllers/StartPophoryViewController.swift b/pophory-iOS/Screen/Auth/ViewControllers/StartPophoryViewController.swift index 69d88b53..3b45af4a 100644 --- a/pophory-iOS/Screen/Auth/ViewControllers/StartPophoryViewController.swift +++ b/pophory-iOS/Screen/Auth/ViewControllers/StartPophoryViewController.swift @@ -7,7 +7,7 @@ import UIKit -class StartPophoryViewController: BaseViewController { +final class StartPophoryViewController: BaseViewController { lazy var startPophoryView = StartPophoryView() diff --git a/pophory-iOS/Screen/HomeAlbum/HomeAlbumView.swift b/pophory-iOS/Screen/HomeAlbum/HomeAlbumView.swift index 66402a91..9f02c241 100644 --- a/pophory-iOS/Screen/HomeAlbum/HomeAlbumView.swift +++ b/pophory-iOS/Screen/HomeAlbum/HomeAlbumView.swift @@ -238,4 +238,8 @@ extension HomeAlbumView { func setMaxPhotoCount(_ maxPhotoCount: Int) { self.maxPhotoLimit = maxPhotoCount } + + func setPhotoCount(_ photoCount: String) { + self.statusLabelText = photoCount + } } diff --git a/pophory-iOS/Screen/HomeAlbum/HomeAlbumViewController.swift b/pophory-iOS/Screen/HomeAlbum/HomeAlbumViewController.swift index 24385b44..1b93d209 100644 --- a/pophory-iOS/Screen/HomeAlbum/HomeAlbumViewController.swift +++ b/pophory-iOS/Screen/HomeAlbum/HomeAlbumViewController.swift @@ -94,7 +94,7 @@ extension HomeAlbumViewController { homeAlbumView.albumImageView.image = ImageLiterals.albumCoverList[coverIndex] } - homeAlbumView.statusLabelText = String(album.photoCount ?? 0) + homeAlbumView.setPhotoCount(String(album.photoCount ?? 0)) homeAlbumView.updateProgressBarWidth(updateWidth: progressValueUnwrapped) diff --git a/pophory-iOS/Screen/Mypage/View/MyPage/MyPageRootView.swift b/pophory-iOS/Screen/Mypage/View/MyPage/MyPageRootView.swift index d6372a3e..7397ccbb 100644 --- a/pophory-iOS/Screen/Mypage/View/MyPage/MyPageRootView.swift +++ b/pophory-iOS/Screen/Mypage/View/MyPage/MyPageRootView.swift @@ -17,7 +17,7 @@ protocol MyPageRootViewDelegate: NSObject { func handleOnAd() } -class MyPageRootView: UIView { +final class MyPageRootView: UIView { // MARK: - Properties