Don't appear dialog when ckeck update as .onForeground
keyboardseokmin opened this issue · comments
Info
- Siren Version: 5.8.1
- Test device: iphone7, version 15.0
Problem
- Check update as .onForeground (Siren.shared.wail(performCheck: .onForeground))
- If user swipe down the notification center screen to the bottom of screen (by swiping downward from the very top of the device's screen)
- And back to app can't appear update dialog
Reason
If swipe down the notification center screen to the bottom of screen
iOS call observer like this
- starting to swipe down : willResignActiveNotification
- reached to bottom : didBecomeActiveNotification, willResignActiveNotification
What i solved
private var appDidBecomeActiveWorkItem: DispatchWorkItem?
private extension Siren {
/// Adds an observer that listens for app launching/relaunching.
func addForegroundObservers() {
guard applicationDidBecomeActiveObserver == nil else { return }
applicationDidBecomeActiveObserver = NotificationCenter
.default
.addObserver(forName: UIApplication.didBecomeActiveNotification,
object: nil,
queue: nil) { [weak self] _ in
guard let self = self else { return }
self.appDidBecomeActiveWorkItem = DispatchWorkItem {
self.performVersionCheck()
}
DispatchQueue.main.asyncAfter(deadline: .now() + 0.02, execute: self.appDidBecomeActiveWorkItem!)
}
}
/// Adds an observer that listens for when the user enters the app switcher
/// and when the app is sent to the background.
func addBackgroundObservers() {
if applicationWillResignActiveObserver == nil {
applicationWillResignActiveObserver = NotificationCenter
.default
.addObserver(forName: UIApplication.willResignActiveNotification,
object: nil,
queue: nil) { [weak self] _ in
guard let self = self else { return }
self.appDidBecomeActiveWorkItem?.cancel()
self.appDidBecomeActiveWorkItem = nil
self.presentationManager.cleanUp()
}
}
if applicationDidEnterBackgroundObserver == nil {
applicationDidEnterBackgroundObserver = NotificationCenter
.default
.addObserver(forName: UIApplication.didEnterBackgroundNotification,
object: nil,
queue: nil) { [weak self] _ in
guard let self = self else { return }
self.presentationManager.cleanUp()
}
}
}
}
Can you open a PR to show the differences? Thanks.
Can you open a PR to show the differences? Thanks.
Of course, just opened a PR : )