I’m running into a problem with remote push notifications on iOS.
When the app is in background or inactive, tapping a notification correctly triggers:
userNotificationCenter(_:didReceive:withCompletionHandler:)
…but when the app is killed, tapping the notification launches the app, yet no delegate method fires and my tracking event never gets sent.
I’m using:
-
SwiftUI @ main App
-
@ UIApplicationDelegateAdaptor for the AppDelegate
-
UNUserNotificationCenter delegate set manually
-
FirebaseAppDelegateProxy disabled
-
No SceneDelegate
I’ve tried:
-
Checking launchOptions?[.remoteNotification] (not fired on iOS 15+)
-
Adding application(_:continue:restorationHandler:)
-
Preventing banners during launch (suggestion by chatGPT but made no difference)
Foreground + background tap handling works perfectly — only killed → tap → launch fails to deliver the payload. hell i can’t even see logging for that flow.
Some code i have:
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate {
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions:[UIApplication.LaunchOptionsKey : Any]?
) -> Bool {
UNUserNotificationCenter.current().delegate = self
return true
}
func userNotificationCenter(
_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void
) {
handleNotificationTap(response.notification.request.content.userInfo)
completionHandler()
}
public func handleNotificationTap(_ userInfo: [AnyHashable : Any]) {
let id = userInfo["notification_id"]
let notificationId = (id as? Int).map(String.init) ?? (id as? String)
if let finalId = notificationId {
Analytics.track("notification_opened", parameters: ["notification_id": finalId])
} else {
Analytics.track(
"notificationTappedWithoutID",
parameters: ["payload": userInfo]
)
}
}
As you can see there should always be some event send, but currently i receive none. i also tried didReceiveRemoteNotification but that didn’t work either.
Any help would be appreciated. been looking in to this for a few nights now.