반응형

Combine Publisher로 Background나 Foreground 진입시 처리하는 방법은 다음과 같습니다.

var cancellableBag = Set<AnyCancellable>()

NotificationCenter.default.publisher(for: UIApplication.willResignActiveNotification)
.sink { [weak self] _ in
    guard let self else { return }
    // Background 진입시 처리
}.store(in: &cancellableBag)

NotificationCenter.default.publisher(for: UIApplication.willEnterForegroundNotification)
.sink { [weak self] _ in
    guard let self else { return }
    // Foreground 진입시 처리
}.store(in: &cancellableBag)
반응형
Posted by 까칠코더
,