forked from sopt-makers/SOPT-iOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Fix] LifecycleAdapter 위치 이동 : SOPT-iOS 모듈로 이동 (sopt-makers#319)
* [Fix] LifecycleAdapter 위치 이동 : SOPT-iOS 모듈로 이동 * [Etc] Demo App target에도 Adapter 추가
- Loading branch information
Showing
4 changed files
with
65 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
SOPT-iOS/Projects/SOPT-iOS/Sources/AppLifecycleAdapter/AppLifecycleAdapter.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// | ||
// AppLifecycleAdapter.swift | ||
// SOPT-iOS | ||
// | ||
// Created by Ian on 12/3/23. | ||
// Copyright © 2023 SOPT-iOS. All rights reserved. | ||
// | ||
|
||
import Core | ||
import Networks | ||
|
||
import UIKit | ||
|
||
final public class AppLifecycleAdapter { | ||
private let cancelBag = CancelBag() | ||
private let authService = DefaultAuthService() | ||
} | ||
|
||
// MARK: - Private functions | ||
extension AppLifecycleAdapter { | ||
public func prepare() { | ||
self.onWillEnterForeground() | ||
self.onWillEnterBackground() | ||
} | ||
|
||
//MARK: - Usecases | ||
private func onWillEnterForeground() { | ||
NotificationCenter.default | ||
.publisher(for: UIApplication.willEnterForegroundNotification) | ||
.subscribe(on: DispatchQueue.global()) | ||
.receive(on: DispatchQueue.main) | ||
.sink(receiveValue: { [weak self] _ in | ||
self?.reissureTokens() | ||
}).store(in: self.cancelBag) | ||
} | ||
|
||
private func onWillEnterBackground() { } | ||
} | ||
|
||
// MARK: - Private functions | ||
extension AppLifecycleAdapter { | ||
private func reissureTokens() { | ||
guard UserDefaultKeyList.Auth.appAccessToken != nil else { return } | ||
|
||
self.authService.reissuance { _ in } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters