-
Notifications
You must be signed in to change notification settings - Fork 6
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
[Fix] #476 - 습관 인증 스톱워치 백그라운드에서 멈추는 문제 해결 #477
Changes from all commits
1f312c0
4219c00
ec45a3e
ccdcf7a
1ca1d7a
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 |
---|---|---|
|
@@ -50,6 +50,13 @@ class AuthTimerVC: UIViewController { | |
navigationController?.interactivePopGestureRecognizer?.delegate = self | ||
} | ||
|
||
override func viewWillDisappear(_ animated: Bool) { | ||
super.viewWillDisappear(animated) | ||
|
||
NotificationCenter.default.removeObserver(self, name: NSNotification.Name(Const.UserDefaultsKey.sceneWillEnterForeground), object: nil) | ||
NotificationCenter.default.removeObserver(self, name: NSNotification.Name(Const.UserDefaultsKey.sceneDidEnterBackground), object: nil) | ||
} | ||
|
||
// MARK: - Methods | ||
|
||
private func setUI() { | ||
|
@@ -93,6 +100,7 @@ class AuthTimerVC: UIViewController { | |
|
||
private func setNotification() { | ||
NotificationCenter.default.addObserver(self, selector: #selector(resetTimer(_:)), name: .resetStopWatch, object: nil) | ||
NotificationCenter.default.addObserver(self, selector: #selector(checkBackgroundTimer), name: NSNotification.Name(Const.UserDefaultsKey.sceneWillEnterForeground), object: nil) | ||
} | ||
|
||
private func setButton(_ button: UIButton, title: String, backgroundColor: UIColor, isEnable: Bool) { | ||
|
@@ -103,7 +111,7 @@ class AuthTimerVC: UIViewController { | |
button.layer.cornerRadius = 2 | ||
} | ||
|
||
func dismissAuthTimerVC() { | ||
private func dismissAuthTimerVC() { | ||
if timeLabel.text != "00:00:00" { | ||
guard let dialogVC = UIStoryboard(name: Const.Storyboard.Name.dialogue, bundle: nil).instantiateViewController(withIdentifier: Const.ViewController.Identifier.dialogue) as? DialogueVC else { return } | ||
dialogVC.dialogueType = .exitTimer | ||
|
@@ -118,6 +126,18 @@ class AuthTimerVC: UIViewController { | |
} | ||
} | ||
|
||
private func timeFormatter(_ intTime: Int) -> String { | ||
let hour = intTime / 3600 | ||
let min = (intTime % 3600) / 60 | ||
let sec = (intTime % 3600) % 60 | ||
|
||
let hourStr = hour < 10 ? "0\(hour)" : String(hour) | ||
let minStr = min < 10 ? "0\(min)" : String(min) | ||
let secStr = sec < 10 ? "0\(sec)" : String(sec) | ||
|
||
return "\(hourStr):\(minStr):\(secStr)" | ||
} | ||
|
||
// MARK: - @objc | ||
|
||
@objc | ||
|
@@ -150,16 +170,14 @@ class AuthTimerVC: UIViewController { | |
} | ||
} | ||
|
||
func timeFormatter(_ intTime: Int) -> String { | ||
let hour = intTime / 3600 | ||
let min = (intTime % 3600) / 60 | ||
let sec = (intTime % 3600) % 60 | ||
|
||
let hourStr = hour < 10 ? "0\(hour)" : String(hour) | ||
let minStr = min < 10 ? "0\(min)" : String(min) | ||
let secStr = sec < 10 ? "0\(sec)" : String(sec) | ||
|
||
return "\(hourStr):\(minStr):\(secStr)" | ||
@objc | ||
func checkBackgroundTimer(_ notification: NSNotification) { | ||
if let isValid = timer?.isValid { | ||
if isTimerOn && isValid { | ||
let time = notification.userInfo?["time"] as? Int ?? 0 | ||
currentTimeCount += time | ||
} | ||
} | ||
Comment on lines
+173
to
+180
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 포그라운드에서 백그라운드로 갈때는 notification 에 time 이 없어서 if let 같은 구문보다 위와 같이 옵셔널을 바인딩한 부분 좋은 거 같아요 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 아 저 이것저것 해볼때 포그라운드에서 백그라운드로 갈 때 타이머를 멈춰주는 함수를 넣느라 그때 썼던건데 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 굳굳 덕분에 좋은 노티 알고가요~ |
||
} | ||
|
||
@objc | ||
|
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.
와아..이렇게 할수 있군여 굳아이디어...!