Skip to content

Commit b137ffd

Browse files
authored
alerts not shown when app in foreground (#646)
## Summary When the device receives a remote notification to display an alert, either a) the app is not in the foreground and the alert is shown in the Notification Center or b) the app is in the foreground and thus far no alert was shown at all - neither in the app nor in iOS's Notification Center. *For UI changes including screenshots of before and after is great.* ## Validation Dropped a particularly formatted .apns json file onto the simulator. Perhaps this fixes #460.
1 parent 8fef064 commit b137ffd

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

BeeSwift/AppDelegate.swift

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import AlamofireNetworkActivityIndicator
1717
import BeeKit
1818

1919
@UIApplicationMain
20-
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate {
20+
class AppDelegate: UIResponder, UIApplicationDelegate {
2121
let logger = Logger(subsystem: "com.beeminder.beeminder", category: "AppDelegate")
2222
let backgroundUpdates = BackgroundUpdates()
2323

@@ -41,6 +41,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
4141

4242
NetworkActivityIndicatorManager.shared.isEnabled = true
4343

44+
UNUserNotificationCenter.current().delegate = self
45+
4446
NotificationCenter.default.addObserver(self, selector: #selector(self.handleGoalsUpdated), name: GoalManager.NotificationName.goalsUpdated, object: nil)
4547
NotificationCenter.default.addObserver(self, selector: #selector(self.handleUserSignedOut), name: CurrentUserManager.NotificationName.signedOut, object: nil)
4648

@@ -161,12 +163,6 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
161163
}
162164
}
163165

164-
// MARK: - UNUserNotificationCenterDelegate
165-
166-
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
167-
completionHandler([.list, .banner, .sound, .badge])
168-
}
169-
170166
private func resetStateIfUITesting() {
171167
if ProcessInfo.processInfo.arguments.contains("UI-Testing") {
172168
UserDefaults.standard.removePersistentDomain(forName: Bundle.main.bundleIdentifier!)
@@ -177,3 +173,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD
177173
UNUserNotificationCenter.current().removeAllPendingNotificationRequests()
178174
}
179175
}
176+
177+
// MARK: - UNUserNotificationCenterDelegate
178+
179+
extension AppDelegate: UNUserNotificationCenterDelegate {
180+
func userNotificationCenter(_ center: UNUserNotificationCenter,
181+
willPresent notification: UNNotification) async -> UNNotificationPresentationOptions {
182+
[.list, .banner, .sound, .badge]
183+
}
184+
}

0 commit comments

Comments
 (0)