Remove single notification from notification center iOS - ios

I want to implement same notification feature in my app just like in-built Mail application of iOS devices?
In Mail application single notification get removed out of many from notification center when user view it?
I have searched for same and got answer for removing all notifications by using
[UIApplication sharedApplication].applicationIconBadgeNumber = 0;
But I don't want to remove all at once, I want to implement it same as in-built Mail application. Can anybody help on this?

Try this code,
[UIApplication sharedApplication].applicationIconBadgeNumber = MAX([UIApplication sharedApplication].applicationIconBadgeNumber - 1, 0);

Related

How to find out the Icon Badge count?

I'm using push notifications on my iOS app and everything is working great.
The icon badge is working and when I open the app I clear it with this code:
[[UIApplication sharedApplication] setApplicationIconBadgeNumber: 0];
But before clearing it I would like to find out what is the badge count to make some changes on the app according to the number of notifications the user has when opening the app.
Is it possible to do get this number?
Thanks!
[UIApplication sharedApplication].applicationIconBadgeNumber
Try

Dismiss apple push notifications when clicked

So it's a pretty straight forward problem. My server sends an APN to the iOS device, I can click on the notification and the app launches and everything works as it should, but the notification never gets dismissed, it just sits there in notification centre.
Any help would be greatly appreciated!
Apologies if this has been answered before, I've searched all over stack and only found reference to local notifications.
Edit
Ok, so when I put
[UIApplication sharedApplication].applicationIconBadgeNumber=0;
[[UIApplication sharedApplication] cancelAllLocalNotifications];
in the application:didFinishLaunchingWithOptions it dismisses any old notifications when the app is launched (and no this doesn't happen by default when the app launched anyway), but when I put it in any of the other delegate methods that get called when the app becomes active like applicationDidBecomeActive: it doesn't work?
This is making very little sense...
Adding in:
application.applicationIconBadgeNumber = 0;
into applicationDidBecomeActive: did the trick!

How can we remotely dismiss a Push Notification?

My app daily broadcasts a Push Notification (PN) to all users which becomes irrelevant after 4 hours. Is there any way I can remove that notification on every user's notification centre that has not tapped it within those 4 hours?
I used to think this is not possible yet, but became hopeful after seeing the Google's Hangout app behaviour - It sends PN to Mac & iOS... and if I read the message on Mac, it automatically immediately removes it from iOS' Notification Center.
I did extensive research on google, surprisingly found nothing on this - just one question here which has been duly closed!
The trick is to make your app support background fetching and handle the push notification when you app is in the background.
Then in the application:didReceiveRemoteNotification:fetchCompletionHandler: set the application badge to 0 so that all you push notification are removed from the notification center.
Send a special push notification where there is not data displayed to user but does contain a an command to reset the push notification state.
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler {
if([[userInfo objectForKey:#"reset"] boolValue]){
[[UIApplication sharedApplication] setApplicationIconBadgeNumber: 0];
}
}
It is only possible to dismiss a notification once the user has tapped. You can't dismiss on hide it if the user hasn't tapped it to open.
If you want to dismiss an opened notification, you can try cancelLocalNotification: to dismiss a notification that is presenting an alert at present.
According to apple documentation:
You can cancel a specific scheduled notification by calling cancelLocalNotification: on the application object, and you can cancel all scheduled notifications by calling cancelAllLocalNotifications. Both of these methods also programmatically dismiss a currently displayed notification alert.

iOS 7 Local notifications with no sound by default

When I run the app on my iOS 7 device, the app doesn't appear on the device notifications settings and doesn't sounds when a notification is being fires. Only after the first notification is being fired, I can see my app under the list of the notification settings with sounds turned off.
Why doesn't the app show in the notifications list initially?
Why are the sounds turned off by default?
On iOS 5&6 I don't have these problems. These are local notifications.
It looks like iOS 7.0.3 includes a fix for that.
Have you set the applicationIconBadgeNumber in "- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions"? Comment this code, and try again.....I don't why, but I got the same problem. After I commented this line, my app works correctly.
I got this same problem. What i found out was, i have a piece of code that caused this all along.
In my AppDelegate didFinishLaunchingWithOptions, i have implemented:
//remove this if you have it
[[UIApplication sharedApplication] setApplicationIconBadgeNumber: 0]; //to reset the badge everytime the app loads
So what i did, I removed that code & redeploy the app. Now it has ON default value in Notification Center.
Phew.
Hmm,
Interestingly, I changed the order of
notification.SoundName = UILocalNotification.DefaultSoundName;
notification.ApplicationIconBadgeNumber = 1;
to
notification.ApplicationIconBadgeNumber = 1;
notification.SoundName = UILocalNotification.DefaultSoundName;
and it works now. When the app is running in background, the local notification fires and plays the default notification sound.

Remove single remote notification from Notification Center

my app receives remote notification from Apple server.
Is there a way to remove a single remote notification from notification center (the drop-down menu available from iOs 5.0+), when the user taps on it?
Thanks!
There is no way to remove a specific notification as of iOS SDK 5.0. The way to remove all the notifications from your app so they don't show in the Notification Center when the user opens the app from one of them, is to set the app badge to 0, like this:
[UIApplication sharedApplication].applicationIconBadgeNumber = 0;
EDIT: on iOS 8, SpringBoard seems to be automatically dismissing a notification when you tap on it on the Notification Center to open the app.
Here is a suggestion, though it does have its flaws, and I haven't tried it myself:
Push a silent notification (contentAvailable:true), don't include a "alert" inside the push, place the alert text in a custom property of the push
Handle the incoming push and trigger a local notification, display it immediately
If the user clicks the local notification, use the [UIApplication cancelLocalNotification:] which should remove the notification from the notification center.
When you call the method:
[application cancelAllLocalNotifications];
inside the AppDelegate methods:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
and
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
All Local and Push Notifications will be remove on that for the particular app.

Resources