All Notifications Disappearing After Opening One of Them

All notifications disappearing after opening one of them

By setting the applicationIconBadgeNumber to 0, you also remove every notification from the notification center.

This has also been discussed here:
iOS application: how to clear notifications?

Furthermore, it is not possible to programmatically remove a single notification, but from iOS8 on, the OS will handle this for you when a user taps a single notification. This has also been discussed here:
Remove single remote notification from Notification Center

All Notification is hidden when i clicked one of them

I have done like this in appdelegate

func applicationDidBecomeActive(application: UIApplication) {
application.applicationIconBadgeNumber = 0;
}

so every time if I open the app then its make applicationIconBadgeNumber to Zero and if applicationIconBadgeNumber is zero its clear all notification from notification center.

How to prevent a notification disappear from notification center when another one is opened? iOS

I know it's a pretty old question, but since it doesn't have an answer, I'll tell you how I solved this issue.

In short, the issue is caused by setting UIApplication.shared.applicationIconBadgeNumber to 0; it's making all of the notifications to be removed from the notification center.

The solution is to set the applicationIconBadgeNumber to the real number of notifications the user has in the notification center. I made a function for this:

func updateIconBadge() {
UNUserNotificationCenter.current().getDeliveredNotifications { notifications in
DispatchQueue.main.async {
UIApplication.shared.applicationIconBadgeNumber = notifications.count
}
}
}

Now you can call this function in the methods application(_application:, didFinishLaunchingWithOptions:), applicationWillEnterForeground(_application:), applicationDidBecomeActive(_application:) in AppDelegate.swift to make sure it will update when it should be.

Push notifications disappear if received while app not running

It seems like the push notifications were disappearing because when the app was launched in the background and executed application:didFinishLaunchingWithOptions: it was re-registering for remote notifications. Re-registering seems to discard any queued messages.

My solution was to check if the app was being launched in the background due to a push notification before calling the push registration method. I'm using the Kinvey SDK, so the following code uses Kinvey's methods, but I strongly suspect this solution will apply to other push registration methods, including the standard UIApplication.registerForRemoteNotifications.

The code that was causing my problem was:

func application(application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool
{
// Initialize Kinvey SDK singleton
KCSClient.sharedClient().initializeKinveyServiceForAppKey("myappid",
withAppSecret: "mysecret",
usingOptions: nil)

KCSPush.registerForPush()
// rest of method...
}

I solved the problem by changing it to:

func application(application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool
{
// Initialize Kinvey SDK singleton
KCSClient.sharedClient().initializeKinveyServiceForAppKey("myappid",
withAppSecret: "mysecret",
usingOptions: nil)

if let _ =
launchOptions?[UIApplicationLaunchOptionsRemoteNotificationKey] as? NSDictionary {

let appState: UIApplicationState = UIApplication.sharedApplication().applicationState

if appState == .Active || appState == .Inactive {
KCSPush.registerForPush()
}
} else {
KCSPush.registerForPush()
}
// rest of method...
}

Now when an app is launched into the background by an incoming push notification, it doesn't re-register for push, and the notification remains in the iOS Notification Center until the user taps it or launches the app manually.

Push notification doesn't show or gets disappeared right away [CodenameOne]

Bug resolved my removing android.background_push_handling=true from build hints in codenameone_settings.properties

Android Heads-up notification disappears after a few seconds

Duration of heads-up notification can't be changed It is set at OS level Depends on OS how much time it provides for it.



Related Topics



Leave a reply



Submit