Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Remove Push Notification in Notification Center after viewed

Is there any way to handle the push notification from the Notification Center after being tap, and remove it when my application has already launched?

like image 555
Vincent Bacalso Avatar asked Nov 21 '11 02:11

Vincent Bacalso


People also ask

How do I turn off notifications on notification center?

To disable lock screen notifications completely, you'll need to visit Settings > Notifications. In the list of apps, tap the app that is sending notifications, then uncheck “Lock Screen” in the “Alerts” options. Repeat with any app whose notifications you'd like to hide on the lock screen. Good luck!

Can you see past notifications on iPhone?

Notification Center shows your notifications history, allowing you to scroll back and see what you've missed. There are two ways to see your alerts from the Notification Center: From the Lock Screen, swipe up from the middle of the screen. From any other screen, swipe down from the center of the top of your screen.


1 Answers

I know this is hack and slash, but you can clear all notifications by changing the badge number on your application.

- (void)application:(UIApplication*)application didReceiveRemoteNotification (NSDictionary*)payload
{
    NSLog(@"Received notification: %@", payload);
    //swapping between two badge numbers to clear notifications
    [[UIApplication sharedApplication] setApplicationIconBadgeNumber:1];
    [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
    ...
}

If you already had a badge number you don't want to lose (above example will simply clear badge number in the end) you can do something like

- (void)application:(UIApplication*)application didReceiveRemoteNotification (NSDictionary*)payload
{
    NSLog(@"Received notification: %@", payload);
    /*
     storing current badge number then swapping between 2 values to make sure we 
     clear the badge number. Once this is done set badge number back to original 
     value.
    */
    int badgeNum = [[UIApplication sharedApplication] applicationIconBadgeNumber]
    [[UIApplication sharedApplication] setApplicationIconBadgeNumber:1];
    [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
    [[UIApplication sharedApplication] setApplicationIconBadgeNumber:badgeNum];
    ...
}

This may not be best practice, but it gets the job done and the client will not know the difference. I like to call it a temp. fix until I stumble upon a better solution. Hope this helps someone!

like image 172
NicholasTGD Avatar answered Nov 15 '22 12:11

NicholasTGD