So I've got a UILocalNotification setup to change the Icon badge.
[myNote setApplicationIconBadgeNumber:[[UIApplication sharedApplication] applicationIconBadgeNumber]+1];
So it works fine if I don't change the badge number after I set it. If the badge shows 2, lets say, when I set the notification, it changes to 3 when the notification goes off. But lets say that I change it from 2 to 5 within the app before the notification fires, it still changes it to 3 when it does fire.
I need it to be able to add 1 to the current badge number, not the number that the badge showed when I first scheduled the notification. Ex: If it's 2 when I schedule the notification, then change it to 5 in the app, the notification should change it 6 when it does fire.
Is there a way to do it? I'm beginning to hate UILocalNotification.
Thanks guys!
Unfortunately, there is no such API. You can, however, discard all your previous notifications and reschedule them with the updated badge number. But I agree with you, local notifications and badge numbers are bound to reach a brick wall and annoy you.
Related
I have to clear application badge icon while opening the application. I do clear by setting applicationBadgeIcon to 0.
=> But it clears my all notifications from notification center. I have also tried by setting applicationBadgeIcon to -1, But it also did not work for me.
Is ther Any solution?
UIApplication.shared.applicationIconBadgeNumber = 0 // Badge count was removed.
Its working fine for me in Swift 4
The thing you need to achieve will not possible if you pass the badge in payload of the push notification. If you any how achieve this behaviour then do one thing remove badge number from payload then you did not bother about to clear badge count and your push still display in notification
disadvantage:
1) user need to remove all notification one by one same like instagram
Otherwise there is no way to achieve this.
I am working on an app that can receive Push-Notifications.
When a notification is received, I need to change the number of the icon's badge and increment it.
Those notifications are stored in a UITableView in my app.
When a row is pressed, this means that the notification has been read so I want to decrement the badge.
I am new to push notifications and badges and I really couldn't find any efficient way to do it
any solutions ?
Thank you.
You can't automatically increment a badge from a notification. Your notification payload must contain the badge property that will be set to the exact value you want for your badge.
To set the badge value from within your app, you can use:
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:someInteger];
If you want to increment the badge by one every time you receive a notification, you need to keep track of your user's badge server-side.
For example, if you send 3 notifications to an user, you will have a badge column in your database for this user with 3 as a value. If the user opens his app and taps one of the notifications, your app will have to set the badge icon to 2 and send a request to your server to decrease the database value to 2.
TL;DR: There is no such thing as a badge:+1 or badge:autoincrement in a notification's payload. You have to keep track of the badge's value server-side.
I'm working on a project on iOS 7, 8 that use a lot of notifications (Remote, Local). I have some questions about Local Notification.
I'm using Local Notification to schedule an alarm or a count-down. As I know, the use of NSTimer is not really a good choice since it has only up to 10' in background & if the app process is killed it doesn't work anymore. Local Notification is managed by iOS but I have to accept its alert when the app is not in foreground. There's nothing like silent local notification (local notification without alert, sound or badge and app still knows about it although it's in background). Am I right ?
Let's assume that there're some simple local notifications in Notification Center, scheduled by our app. Normally when I touch on a notification to see it in my app, the others remain present until we interact with them. In some cases that I haven't figured out, all other notifications are removed from the Notification Center. Does anyone encounter this & understand why ?
I find the interactive notification feature in iOS very limited. I want to change the title of a defined UIMutableUserNotificationAction button & add an image for it, like I can do with UIButton. So the question is : Is it possible to customize the UI of an action button ?
Thanks for your help !
Unfortunately there is no correspondence in silent notification using local notifications.
The number of the visible notification in the notification center is a user decision, the user in Settings can decide to set a different number or decide to do not show them in notification center as well. As for the first point no. The third point is not clear, you can set the image you want for a remote just put in the payload the right name, local notifications use the app icon.
There is no silent notification for Local Notification. The user has to click to the notification to open your App.
I suppose that the associated application has deleted those notifications programmatically. Else, those notifications must stay in the notification center.
You cannot add image to action buttons but just the titles.
I tried more than two weeks to do the same. I had to show notification after 2 hrs even if the use doesn't click the notification. But the repetition facility is well handled in objective C. I could have created multiple local notification but it will also violates the total number of 64 notifications. Apple needs to improved the same.
This question already has answers here:
iOS badge number live update
(3 answers)
Closed 8 years ago.
I have an app that I want to update the badge icon weekly. I see that at least pre iOS7, UILocalNotification could only set the badge icon to a specific number like
someLocalNotification.applicationIconBadgeNumber = 42;
But I want my app to load in the background lets say every sunday, do a calculation based to get the difference between the current date and some start date, and update the badge number accordingly.
UILocalNotification can't do this apparently. It looks like push notifications can, but I don't have a server component for this app, so using that as a workaround wouldn't work, and I'm not sure Apple would like it anyway.
I know there is some background app refresh updates in iOS7, but I'm not sure if they would work in this situation.
TLDR: How do I update a badge icon in iOS7 that requires a bit of calculation to get the correct number, on a weekly basis (or any arbitrarily long time basis)? And I want to do this background updating without a server component.
You simply schedule a silent local notification, with a nil message and then update the badge number. Also set the repeat count to nil otherwise the badge wont get updated if you call this local notification multiple times
This person posted a similar question, have a look
My app is queuing local notifications (and can also receive APNs) and the app's icon badge is getting set as a consequence.
When the app launches I want to clear the icon badge but I want the notifications to remain in the notification center history lists. But it seems this isn't possible? Setting the badge count to 0 has the effect of removing all notifications from the notification center.
Is there any way I can leave them there so it is the user's responsibility to remove them, yet at the same time clear the app's badge?
No, unless something has recently changed, the notifications in Notification Center are tied to the applications icon badge.
This code reads like it should clear only the badge, however, it is commonly used to clear the notifications in Notification Center:
[UIApplication sharedApplication].applicationIconBadgeNumber = 0;
However, when the code is used, the Notification Center notifications are cleared as well. Notification Center reads what to display based on what is displayed on the icon.
Sources:
My own experience
This previous question