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?
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!
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.
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With