-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature] background상태에서 foreground진입시 일정시간 이후 앱 초기화 로직 생성 (#626)
* [Feature] background상태에서 foreground진입시 일정시간 이후 앱 초기화 로직 생성 * feat: timeout 시간 5초 -> 10분으로 수정
- Loading branch information
1 parent
ebec0f0
commit 9d01c76
Showing
5 changed files
with
59 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// | ||
// SSTimeOut.swift | ||
// susu | ||
// | ||
// Created by MaraMincho on 10/14/24. | ||
// Copyright © 2024 com.oksusu. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import OSLog | ||
import SSNotification | ||
|
||
final class SSTimeOut { | ||
private nonisolated(unsafe) static let shared = SSTimeOut() | ||
private var timeoutInterval: Int = 60 * 10 | ||
private var enteredBackgroundDate: Date? | ||
|
||
static func setTimeoutInterval(minute: Int, seconds: Int) { | ||
shared.timeoutInterval = minute * 60 + seconds | ||
} | ||
|
||
static func enterBackground() { | ||
os_log("백그라운드 진입") | ||
shared.enteredBackgroundDate = Date.now | ||
} | ||
|
||
static func enterForegroundScreen() { | ||
os_log("포그라운드 진입") | ||
defer { | ||
shared.enteredBackgroundDate = nil | ||
} | ||
guard let backgroundEnteredDate = shared.enteredBackgroundDate else { | ||
return | ||
} | ||
let interval = Date.now.timeIntervalSince(backgroundEnteredDate) | ||
|
||
if shared.timeoutInterval < Int(interval) { | ||
NotificationCenter.default.post(name: SSNotificationName.resetApp, object: nil) | ||
} | ||
} | ||
} |
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
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