-
Notifications
You must be signed in to change notification settings - Fork 0
refactor, feat: 네트워크 리팩토링, 점검 페이지 구현 #362
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
2f0d022
c0bc1f7
c643297
5189d16
db990c3
b067550
e6e9d2f
735b367
d433a77
d8ba11b
8586c47
546a62c
30f1dde
06a77d4
d9fff33
1590f06
09aba0b
1d0c1f3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,7 +10,16 @@ import UIKit | |
| class SceneDelegate: UIResponder, UIWindowSceneDelegate { | ||
|
|
||
| var window: UIWindow? | ||
| var urlParameters: [String: String]? | ||
| private var isPresentingErrorViewController = false | ||
|
|
||
| override init() { | ||
| super.init() | ||
| NotificationCenter.default.addObserver(self, selector: #selector(presentErrorViewController), name: NSNotification.Name("ServerError"), object: nil) | ||
| } | ||
|
|
||
| deinit { | ||
| NotificationCenter.default.removeObserver(self) | ||
| } | ||
|
|
||
| func scene(_ scene: UIScene, | ||
| willConnectTo session: UISceneSession, | ||
|
|
@@ -115,5 +124,33 @@ extension SceneDelegate { | |
| return viewController | ||
| } | ||
|
|
||
|
|
||
| @objc private func presentErrorViewController() { | ||
|
|
||
| guard isPresentingErrorViewController == false else { | ||
| return | ||
| } | ||
| isPresentingErrorViewController = true | ||
|
|
||
| if let navigationController = window?.rootViewController as? UINavigationController { | ||
|
|
||
| let homeViewController = makeHomeViewController() | ||
| let completion: ()->Void = { [weak self] in | ||
| navigationController.setViewControllers([homeViewController], animated: false) | ||
| navigationController.dismiss(animated: true) { | ||
| self?.isPresentingErrorViewController = false | ||
| } | ||
| } | ||
| let errorViewController = ErrorViewController(completion: completion).then { | ||
| $0.modalPresentationStyle = .fullScreen | ||
| } | ||
|
Comment on lines
+143
to
+145
|
||
|
|
||
| if let _ = navigationController.presentedViewController { | ||
| navigationController.dismiss(animated: true) { | ||
| navigationController.present(errorViewController, animated: true) | ||
| } | ||
| } else { | ||
| navigationController.present(errorViewController, animated: true) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,58 +19,89 @@ final class KeychainWorker { | |
| } | ||
| static let shared = KeychainWorker() | ||
|
|
||
| private init() { } | ||
| private init() {} | ||
| private var keychains: [TokenType: String?] = [:] | ||
| private let lock = NSLock() | ||
|
|
||
| func create(key: TokenType, token: String) { | ||
| lock.lock() | ||
| defer { | ||
| lock.unlock() | ||
| } | ||
|
|
||
| let query: NSDictionary = [ | ||
| kSecClass: kSecClassGenericPassword, | ||
| kSecAttrAccount: keyType(key: key), | ||
| kSecValueData: token.data(using: .utf8, allowLossyConversion: false) as Any | ||
| ] | ||
| SecItemDelete(query) | ||
| keychains.removeValue(forKey: key) | ||
|
|
||
| let status = SecItemAdd(query, nil) | ||
| if status != errSecSuccess { | ||
| print("Failed to save token, status code: \(status)") | ||
| if status == errSecSuccess { | ||
| keychains.updateValue(token, forKey: key) | ||
| } else { | ||
| print("Failed to save \(key) token,", SecCopyErrorMessageString(status, nil) ?? "") | ||
| } | ||
| } | ||
|
|
||
| func read(key: TokenType) -> String? { | ||
| lock.lock() | ||
| defer { | ||
| lock.unlock() | ||
| } | ||
|
|
||
| if let token: String? = keychains[key] { | ||
| return token | ||
| } | ||
|
|
||
| let query: NSDictionary = [ | ||
| kSecClass: kSecClassGenericPassword, | ||
| kSecAttrAccount: keyType(key: key), | ||
| kSecReturnData: kCFBooleanTrue as Any, | ||
| kSecMatchLimit: kSecMatchLimitOne | ||
| ] | ||
|
|
||
| var dataTypeRef: AnyObject? | ||
| let status = SecItemCopyMatching(query, &dataTypeRef) | ||
|
|
||
| if status == errSecSuccess { | ||
| if let retrievedData: Data = dataTypeRef as? Data { | ||
| let value = String(data: retrievedData, encoding: String.Encoding.utf8) | ||
| return value | ||
| } else { return nil } | ||
| if status == errSecSuccess, | ||
| let retrievedData: Data = dataTypeRef as? Data, | ||
| let value = String(data: retrievedData, encoding: String.Encoding.utf8) { | ||
| keychains.updateValue(value, forKey: key) | ||
| return value | ||
| } else if status == errSecItemNotFound { | ||
| keychains.updateValue(nil, forKey: key) | ||
| return nil | ||
|
Comment on lines
+72
to
+74
|
||
| } else { | ||
| print("failed to loading, status code = \(status)") | ||
| print("Failed to load \(key) token,", SecCopyErrorMessageString(status, nil) ?? "") | ||
| return nil | ||
| } | ||
| } | ||
|
|
||
| func delete(key: TokenType) { | ||
| lock.lock() | ||
| defer { | ||
| lock.unlock() | ||
| } | ||
|
|
||
| keychains.removeValue(forKey: key) | ||
|
|
||
| let query: NSDictionary = [ | ||
| kSecClass: kSecClassGenericPassword, | ||
| kSecAttrAccount: keyType(key: key) | ||
| ] | ||
| let status = SecItemDelete(query) | ||
| if status == errSecSuccess { | ||
| print("Item successfully deleted") | ||
| } else if status == errSecItemNotFound { | ||
| print("Item not found") | ||
| } else { | ||
| print("Error deleting the item, status code: \(status)") | ||
| } | ||
| if status == errSecSuccess { | ||
| return | ||
| } else if status == errSecItemNotFound { | ||
| print("\(key) token not found") | ||
| } else { | ||
| print("Error deleting \(key) token", SecCopyErrorMessageString(status, nil) ?? "") | ||
| } | ||
| } | ||
| } | ||
|
|
||
| extension KeychainWorker { | ||
|
|
||
| private func keyType(key: TokenType) -> String { | ||
| let keyType: String | ||
|
|
@@ -85,5 +116,4 @@ final class KeychainWorker { | |
| } | ||
| return keyType | ||
| } | ||
|
|
||
| } | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| // | ||
| // ErrorResponseDto.swift | ||
| // koin | ||
| // | ||
| // Created by 김나훈 on 3/18/24. | ||
| // | ||
|
|
||
| import Foundation | ||
|
|
||
| struct ErrorResponseDto: Decodable { | ||
| let code: String | ||
| let message: String | ||
| } | ||
|
|
||
| extension ErrorResponseDto { | ||
| func toDomain(withStatusCode statusCode: Int) -> ErrorResponse { | ||
| return ErrorResponse(statusCode: statusCode, code: self.code, message: self.message) | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The observer is added in
initbut never removed. Even if SceneDelegate is long-lived, it’s safer to remove the observer (e.g. indeinit) or use the block-based API that returns a token you can store and invalidate.