Push notification disappearing with in second from the lock screen!

Push notification disappearing with in second from the lock screen! When we use our app to send push notification it dissappear within seconds or stay for few seconds and sometime its just the sound. Please guide me thank you :(

Sometime I get the exact same behavior and I still don't know why.

safetyandstory did you find the root cause?


Is there anybody with at least few insight on what could generate this behavior?

Thank you!

Usually this happens if the app crashes in background. When it does, the notification center is cleaned up.

This is actually not our problem cause. We don't have crash reports on these events

I am having issue of missing notifications in notification center for new mail on beta 7 since beta 1.

The notifications either dont appear in notification center, or if they appear they disappear whenever the mail app is opened or on their own after 2 minutes.

Problem is not resolved even after Reset All Settings, restore from backup.

Issue reported on bug portal http://bugreport.apple.com.

Problem started after clearing all the notifications from the Notification center manually.

It can be reproduced by doing so again and again.

Saw same thing on Push Notifications, it happens if a second push notification shows up immediately after the first one.

This was driving me crazy but I finally found the fix to this issue:

I was setting the app's badge count in a ViewModel, but the push notification (I have a notification extension) was waking up the app and executing that code in background. If you set the app badge to 0 at some point, all notifications are removed from the lock screen.

Now I have:

Code Block swift
    private func updateAppBadgeIcon() {
        let state = UIApplication.shared.applicationState
        guard state == .active || state == .inactive else { return } /* Skips background update. */
        UIApplication.shared.applicationIconBadgeNumber = /* do your calculations for the badge */
    }


Push notification disappearing with in second from the lock screen!

Hello everyone please try this below snippet

func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
        completionHandler([.sound, .badge, .banner,.list])
}

Note :- just need to add .list in this method so you will get disappear push notification

Thanks

Push notification disappearing with in second from the lock screen!
 
 
Q